cancel
Showing results for 
Search instead for 
Did you mean: 
vikas1606

Environment variable in Power Platform

In Power Platform, environment variables are variables that you can define and use to store values that are used across your solutions. They can be used to store values such as server URLs, API keys, or any other value that may change between environments or need to be accessed by multiple components in your solutions.

 

Environment variables are defined at the environment level and can be accessed by any solution that is part of that environment. This means that if you have multiple solutions within the same environment, you can define an environment variable once and use it across all your solutions.

 

Let’s take an example to understand it’s working.

Suppose we have 3 different environments like development, test, and production. We develop Apps, Automation, and other artifacts in the development environment and then move them to test, and the QA team tests all working functionalities. After getting a sign-off from the QA team we move changes to Production.

 

When we push changes from one environment to another, we must change connections and other environment-related options. We have a SharePoint site and list in one environment then after moving to the test environment we must change all the connections in PowerApps and in Automate.

 

The environment variable can save these efforts and deployment could be an easier task. I am going to take the Power Automate example to demonstrate environment variable use. Below we have two environments Development and Production.

vikas1606_0-1679026251096.png

 

Now, Let’s quickly create an EV. As you can see in the screenshot, we are creating a SharePoint URL variable and setting the current SharePoint URL for the development environment.

vikas1606_1-1679026251104.png

 

vikas1606_2-1679026251105.png

 

vikas1606_3-1679026251109.png

 

I have created a simple flow here to show how we can use the environment variable created in the above step. I have taken the “When an item is created or modified” SharePoint trigger. Here, you can see instead of hard coding the SharePoint site URL using the environment variable and its value we set it at the environment level. You can see in the above screenshot that shows the value of this variable is the Default site value.

image.png

 

If we have done with all changes and the solution is ready to deploy to production. Edit the environment variable and remove the value set to it and click on the save button. So that when we will import the solution to the Production environment it will ask to set the value to this EV.

vikas1606_5-1679026251116.png

Export Solution:

Now, Publish all customizations. Select the solution and click on the export solution. It opens below a window. Click on publish button to publish changes. Although we have already done it asks if there are any other changes we need to publish. After clicking publish button then click on the next button.

vikas1606_6-1679026251118.png

 

vikas1606_7-1679026251122.png

 

The next button will take you to the export this solution option. Here you would see two options managed and unmanaged solutions.

Managed solutions are packaged solutions that are created, tested, and deployed by developers or ISVs (Independent Software Vendors) and are designed to be installed and used by customers or organizations. Once a managed solution is installed in an environment, the components included in the solution become read-only and cannot be modified directly. Managed solutions can be upgraded, uninstalled, or deleted from the environment.

 

On the other hand, unmanaged solutions are customizable solutions that can be created, modified, and managed directly in the environment by developers or administrators. Unmanaged solutions allow users to modify and customize the solution components without any restrictions, and changes can be made and saved directly to the environment. Unmanaged solutions cannot be exported, but they can be used to create managed solutions.

vikas1606_8-1679026251124.png

 

I am selecting a managed solution for the production environment. You can select as per your requirements. Now, Click on the export button and it will start the export process. Once the process would be done it will show an alert message with a download button to download exported solution. click on the download button and it will download the zip file to export.

vikas1606_9-1679026251127.png

 

It is time to deploy the solution to the Production environment. Click on the environment option on the top and select Production environment.

vikas1606_10-1679026251128.png

 

Import Solution to Production environment:

After changing the environment to Production. Click on solutions from the left pane and then click on the Import Solution option on the top.

vikas1606_11-1679026251128.png

 

the above option would open an export window to browse the downloaded solution zip. select the downloaded zip file and click on the next button. It navigates to the below screen to show all the details of the solution files. Verify these details and click on the next button.

vikas1606_12-1679026251131.png

 

Set Environment variable:

vikas1606_13-1679026251133.png

 

The next button will take you to the next window and there it will ask you to set the environment variable value. Here we need to set SharePoint site URL in this variable. Now, once we set the URL then we do not need to go to each action and trigger in all automation and Apps to set the URL.

The environment variable helps here to set the site URL from one place and that it on the time of importing a solution. We do not need to edit Power Automate and manually change SharePoint URLs at all places.

After setting the value click on the import button and it will import the solution to the Production environment.

In summary, environment variables are useful in the Power Platform for centralized and secure configuration management, flexible deployment, and dynamic value resolution.

Comments

Thanks for sharing ! this is something that i was not aware of

Thank you for this. Really helpful. Seems crazy to have to remember to remove the value in the environment variable but it works. Thanks

Environment variables are created as part of a Solution in Power Apps, but can be referenced in Power Automate?

Thanks for the explanation, very useful. Can EV also be used by dataflows using M code?

Thanks for sharing! This is really helpful.

Thanks for sharing.

Thank you very much for sharing this content.

I understand that this would be a way to make the change when the import/export is done manually.

Do you know how this process can be carried out to make this update automatically when using azure devops to incorporate ALM into the solutions?

Thank you very much in advance.

Hi! Thanks for the post.

 

I'm creating a PCF control that needs to work in both a model-driven app and in Power Portals (a.k.a. Power Pages). It needs a GIS rest service url that will differ between our DEV and PROD environments. 

 

Could I access my "GIS rest service url" environment variable (EV) in both model-driven and portals environments using JavaScript? The JS would need to be the same regardless of environment.