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 PowerApps 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

Environmental variables of Power Apps 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 PowerApps 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.

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

This list contains the following columns.

Column NameData Type
IssueTitle (Single Line Text)
Issue DescriptionMulti Line Text
PriorityChoice
StatusChoice
Assigned To Person and Group
Date ReportedDate and Time

Follow the steps below to learn how to use environmental variables.

  • Open PowerApps studio -> Click Solutions in left navigation -> Click +New solution.
  • Now, provide the solution details, then click Create.
  • 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.
  • After creation Save and Publish the App
  • Now you can see the application in the solution.
  • Then, in the app. Go to Settings -> Under General -> toggle On the Automatically create environment variables when adding data sources.
  • Now, add the SharePoint list to the application.
  • Then, the environment variables will be created automatically. 
  • You’ll receive this success message, as in the image below. Click on Manage them here.
  • It will open the solution. Here, you’ll see the created variables.

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.

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

  • 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.

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

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

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.

  • 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.

  • It will open the Edit pane for updating variables. In the Advance section-> Turn Off the Export Value ->Click on Save.
  • Repeat the same step for other environment variables. Then, click on Publish all customizations.
  • Then export the solution by selecting the solution then choose export solution then select unmanaged or managed and export as shown below image

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, and environment variables.

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

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

Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *