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.
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.
- Next, configure your variable.
- Enter a friendly
Namewill be generated automatically. You’ll need this later.
- Optionally, add a
- Select a
Data Type. For this example, we’ll select Text.
- You can enter the
Default Valueif you want, which will be used if your Current Value is empty.
- 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.
- Click on the Data icon.
- Select Add data.
- Search for “Environment.”
- Add the
Environment Variable ValuesData Source.
Repeat the above steps to add the
Environment Variable Definitions Data Source.
- Confirm both data sources have been added.
- Now replace the
Textproperty of the Label control with the formula below. We’re doing a Lookup in the Environment Variables for our variable.
- Set the value to the Name generated for you when you created the Environment Variable.
- 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
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.
Join the newsletter to receive the latest updates in your inbox. After entering your name and email, you can choose Focustivity (PKM and Self Development), Microsoft Roundup, or both.Subscribe