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.
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.
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.
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.
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.
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.
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.
It is time to deploy the solution to the Production environment. Click on the environment option on the top and select Production environment.
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.
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.
Set Environment variable:
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.