Skip to content

How to access environment variables in a Canvas Power App

How to access Environment Variables for text and other data type values from your canvas Power App. Useful for managing settings for environments.

Eric Gregorich
Eric Gregorich
3 min read
An example app with a text label control.

Table of Contents

When deploying Power Apps between environments, you don’t want to update the app after it has been imported to change text, URLs, and other things that are different in the other environment.

Environment Variables are also used for SharePoint Sites and URLs, and I’ll talk about it in another post. Let’s assume you have some simple text values that need to be configured differently between environments. You can use Environment Variables for URLs, settings, colors, and other things.

A Demo App

Here is a straightforward demo app. The only thing I added to this canvas app is a Label control with some default text.

An example app with a text label control.

Let’s imagine we need to deploy this app from my Dev environment to a Production environment. We want the text on the label to be different in the production environment.

Create a Solution

Your Canvas App needs to be in a Solution to use environment variables. Hopefully, you always create apps in Solutions because they have many benefits. If not, you can create a new solution and add your existing app.

Create an Environment Variable

Next, let’s create an Environment Variable.

  • Click New > More > Environment Variable.
Create a new environment variable.
Create a new environment variable.
  • Next, configure your variable.
Configure your environment variable.
Configure your environment variable.
  1. Enter a friendly Display Name.
  2. The Name will be generated automatically. You’ll need this later.
  3. Optionally, add a Description.
  4. Select a Data Type. For this example, we’ll select Text.
  5. You can enter the Default Value if you want, which will be used if your Current Value is empty.
  6. Enter the Current Value. This is what the app will use in each environment.
When you export your Solution to another environment, you’ll need to remove the Current Value from your Environment Variables. Otherwise, the values will override your current values in the destination environment!

Save your variable. Then edit your Canvas App.

Using the Environment Variable in your Canvas App.

To use your variable, you’ll need to add the Environment Variable Values and Environment Variable Definitions Data Sources to your app.

  1. Click on the Data icon.
  2. Select Add data.
  3. Search for “Environment.”
  4. Add the Environment Variable Values Data Source.

Repeat the above steps to add the Environment Variable Definitions Data Source.

  1. Confirm both data sources have been added.
  2. Now replace the Text property of the Label control with the formula below. We’re doing a Lookup in the Environment Variables for our variable.
  3. Set the value to the Name generated for you when you created the Environment Variable.
  4. Your text value should change to whatever value you entered into your Environment Variable.
LookUp(
    'Environment Variable Values',
    'Environment Variable Definition'.'Schema Name' = "eg_DemoTextVariable"
).Value

Conclusion

Now when you export your solution (remember to clear your Current Values in each variable), you can import it into another environment. All you need to change is the Current Value in each Environment Variable.

Once your Environment Variables have a Current Value set, your variable will not be replaced when you import updates in the future.

Power Apps

Eric Gregorich Twitter

I design and build software solutions that help companies and people be more productive.


Related Posts

Name too long error in Power Apps

An error appears in Microsoft Power Apps. There was a problem saving your data. The name could be too long. This only occurs when using the SaveData function to save data to the device. There may be too much data in the collection that is being saved, but the data

Microsoft Power Apps Icons

Microsoft Power Apps has a few icons built-in that we can use in our applications. If you want more options, you can follow these simple steps. ^ 1. Go to the site Power Apps Icons. 2. Search for the icon name to find the one you want. 3. Click the color

Microsoft Power Apps Icons

Power Apps Error Function

Using the Power Apps Error Function.