Post

#PowerPlatformTip 105: 'PowerApps, EnvironmentVariables Without Premium'

#PowerPlatformTip 105: 'PowerApps, EnvironmentVariables Without Premium'

TL;DR: A canvas app can only read an environment variable as a record through the premium Dataverse connector. A solution cloud flow can use environment variables without premium. So let a small flow return the value with Respond to a Power App or flow, call it once with Set(gblSiteUrl, GetConfig.Run().siteurl) and reuse the global variable everywhere in the app.

💡 Challenge

Environment variables are the clean way to keep configuration (a SharePoint site, a list, an email address, a URL) out of your apps and flows and change it per environment. In a solution cloud flow you just pick them from dynamic content. In a canvas app, reading a text value from an environment variable means connecting to the Dataverse tables Environment Variable Definitions and Environment Variable Values, and the Dataverse connector makes the app premium.

✅ Solution

Put a small flow into the same solution. The flow reads the environment variable from dynamic content and returns it to the app with Respond to a Power App or flow. The app calls the flow once and stores the result in a global variable. Neither the Power Apps trigger nor the respond action is premium, and environment variables in a solution flow don’t need a premium connector.

🔧 How It’s Done

1. Create the flow inside the solution.

🔸 In your solution select New → Automation → Cloud flow → Instant, and choose the Power Apps (V2) trigger. The flow has to be in a solution, otherwise environment variables don’t show up in dynamic content.

2. Return the values.

🔸 Add Respond to a Power App or flow and add one Text output per value, for example SiteUrl.

🔸 Fill it from dynamic content. In the Environment variables section you’ll find each variable by its display name. In code view the reference looks like this:

1
@parameters('SharePoint Site (contoso_SharePointSite)')

The text in brackets is the schema name: publisher prefix plus name.

3. Call the flow from the app.

🔸 In Power Apps Studio open the Power Automate pane and add the flow, here called GetConfig.

🔸 In App.OnStart, call the flow once and keep the result:

1
Set(gblSiteUrl, GetConfig.Run().siteurl)

🔸 The output names of the respond action appear in lower case in Power Apps (SiteUrl becomes siteurl). For several values, return them all from the same respond action and store the whole record: Set(gblConfig, GetConfig.Run()), then read gblConfig.siteurl, gblConfig.listname and so on.

4. Use the variable.

🔸 Use gblSiteUrl wherever the app needs the value, for example in Launch(gblSiteUrl) or as text in a label.

🎉 Result

The app gets its configuration from the environment variables of the solution, the same values your flows use. After a solution import into test or production, the app reads the values of that environment, and nobody has to edit the app.

🌟 Key Advantages

🔸 One source of truth: the same environment variable serves apps and flows.

🔸 Per environment: set a different value in each environment, the app picks it up automatically.

🔸 No premium for the app: Power Apps trigger and respond action are standard.

⚠️ Good to Know

🔸 Start time: a flow call takes longer than a local formula, and App.OnStart waits for it. Call the flow once, return all values in one response, and don’t call it on every screen. If the value is only needed on one screen, call the flow in that screen’s OnVisible instead.

🔸 Changed values: when you change an environment variable’s value directly in an environment (not through a solution import), flows keep using the previous value until the flow is saved again or turned off and on. Publishing an updated value can take up to an hour.

🔸 Data source variables are different: for SharePoint data sources, canvas apps can use environment variables directly as the site and list of the connection. This tip is for values you need in formulas.

🎥 Video Tutorial

🛠️ FAQ

1. How can I retrieve environment variables in PowerApps without a premium license?

Use a solution cloud flow with the Power Apps (V2) trigger that reads the environment variable from dynamic content and returns it with Respond to a Power App or flow. The app calls the flow and stores the value in a global variable.

2. Do I need a premium connector to use environment variables in Power Automate?

No. Environment variables are available in the dynamic content of solution cloud flows without a premium connector. Premium only comes in if you read the environment variable tables with the Dataverse connector like normal data.

3. Can I update environment variables centrally?

Yes. Change the current value of the environment variable in the solution of the environment. All apps and flows that use it get the new value; flows pick it up after they are saved again or turned off and on.

4. Where is the value stored that the flow returns?

In Dataverse: the definition (with its default value) in the table Environment Variable Definitions, the current value in Environment Variable Values, at most one value row per definition and environment. If there’s no value row, the default value is used. The dynamic content of the flow already resolves this, so you don’t have to query the tables.

🔸 #PowerPlatformTip 61: ‘Power of Environment Variables’ - the fundamentals of environment variables this trick makes available to canvas apps for free.

🔸 #PowerPlatformTip 20: ‘Change Flow Owner’ - another solution-aware technique worth knowing once this configuration flow lives in a solution.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.