How to Use Environment Variables in Power Platform?

A few weeks back, a requirement came up for building an Issue Tracker application using Power Apps. While exporting this application from the development environment to the testing environment, I found the Power Apps environmental variables very helpful because they made it easy to automatically adjust the URLs and connections without manually doing it.

In this article, I will explain the Power Platform environment variables and how to use environment variables in Power Platform [Power Apps & Power Automate] with a simple example.

Moreover, we will see the following topics:

  • Power Apps update environment variables
  • Power Automate environment variables
  • Update environment variables during import in the Power Apps canvas app

Environmental Variables in Power Apps

Power Apps environmental variables are crucial in importing and exporting Power Apps Solutions. They help store the parameter keys and values, which serve as input to other applications.

While exporting, the parameter keys stay the same, but their values are removed. When importing into another environment, we must provide these keys’ values.

Why We Use Environment Variables in Power Platform

Understand the use of Power Apps environment variables with the help of the simple example below.

Example: I have an application in Power Apps connected with a Power Automate flow. This application and flow are connected to the SharePoint site and list. Now, I need to export this application to other environment users.

Now, they need to update their SharePoint connections in a new environment for this application. At that time, we can use these environment variables. It will take the SharePoint site and list addresses as values for those variables before importing them into the new environment.

So, there is no need to change connections manually everywhere we use in the app.

Environment Variables in Power Apps Canvas App

Let’s see how to use environment variables in Power Apps. I have an Issue tracker application in the production environment. I need to export it to the testing environment.

I created this application to raise issues. Once they submit the issue details, they will be mailed to the assigned people.

powerapps use environment variables

NOTE:

Environment variables can be reused across many different solution components in Power Apps and Power Automate.

For the above application, I have a data source in the SharePoint list named “Issue Tracker.”

powerapps use text environment variables in canvas app

This list contains the following columns.

Column NameData Type
IssueTitle(Single line of text)
Issue descriptionMulti lines of text
PriorityChoice
StatusChoice
Assigned ToPerson or group
Date ReportedDate and Time
Follow the steps below to learn how to use environmental variables.

1. Open PowerApps studio -> Click Solutions in left navigation -> Click +New solution.

power apps solutions

2. Now, provide the solution details, then click Create.

power apps application migration environment variables

3. Enter in to the solution -> Click on +New -> Select App -> Click on Canvas app. It will create one Power Apps application and provide its name.

environment variables in the powerapps

4. Then, in the app. Go to Settings -> Under General -> toggle On the Automatically create environment variables when adding data sources.

power apps environment variables

5. Now, add the SharePoint list to the application.

powerapps environment variables sharepoint list

6. Then, the environment variables will be created automatically. Refer to the image below to see how the variables are created. Click on Save.

environment variables for migration in powerapps

7. You’ll receive this success message, as in the image below. Click on Manage them here.

power automate environment setup

8. It will open the solution. Here, you’ll see the created variables.

power automate environment variable not showing

9. To create an app in the solution, Click +New -> Select App -> Select Canva app.

use environment variable in power apps canvas application

10. Here, I created an issue tracker application. You can make your application using Power Apps.

To create an Issue tracker application, follow the steps below.

  • Take three screens -The welcome screen, the Issue submits screen, and the success screen.
  • In the welcome screen :
    • Add Text label -To display the welcome message.
    • Next arrow icon -> Use Navigate(screen2 name) in its OnSelect property.
  • In the Issue submit screen:
    • Add Edit Form – Connect it with the Issue Tracker SharePoint list. Change Default mode to New.
    • Button control – Use SubmitForm(Form name); Navigate(screen3 name) in it’s OnSelect property.
  • In success screen:
    • Add Text label -To display the success message.

At last, save and publish the application.

10. Now, you can see the application in the solution.

power automate set environmental variable

Power Automate Environment Variables

As I said, the application requires a Power Automate flow to send the issue details to assigned people.

This flow also has connections with the SharePoint list. So, while exporting, we need to change the connection. Therefore, I’m using the environment variables in the Power Automate flow.

1. To create flow in the solution, click on the +New -> Select Automation -> Click on the Cloud flow -> Click on Automated.

how to create environment variable power automate

2. In the flow, add When an item is created, trigger -> To provide the SharePoint site address -> click dropdown ->select Enter custom value -> Choose the environment variable created for SharePoint site.
Repeat the same step for List Name selection.

creating environment variables in power apps

3. As in the image below, create the flow to send an email when an issue is submitted.

how to change the urls of exported powerapps solution between environments

4. Now, the flow is ready. In the solution, you can see the newly created flow.

use environment variable in powerapps canvas app

Power Apps Update Environment Variables [Before Exporting]

Now, the solution is ready to export. Before exporting, we need to update the environment variables. Then, only in the testing environment, the other users provide their SharePoint site address and list name.

Follow the steps below to update the environment variables.

1. In the solution -> Select the Environment Variable -> Click on ellipses()-> Click on Edit.

Note: you can identify the Environment Variables in the solution by check ing the value in Type column.
use data source environment variables in canvas apps

2. It will open the Edit pane for updating variables. In the Advance section-> Turn Off the Export Value ->Click on Save.

power automate update environment variable

Repeat the same step for other environment variables. Then, click on Publish all customizations.

Note: To Export and import solution follow the links.

Update Environment Variables During Import in Power Apps Canvas App

Before importing the solution into another environment in Power Apps. We need to create the SharePoint list precisely as it was in the previous environment.

Look at the image below. While importing, I got this page to update the SharePoint site address, issue tracker list name, and environment variables.

update environment variables during import in power apps canvas app

After providing details, click on the Import button. Then, it will be imported into your environment. Refer to the image below.

use environment variable in power apps canvasapp

You can run the application in this environment now. Like this, the environment variables will help you change the connections between export and import.

Also, you may like:

I hope you found this helpful article. Use it as a reference when you’re trying to run the Power Apps application in another environment to update the SharePoint connection.

>