| Mohsin Ahmed
In this blog, we are going to look at environment variables in Power Platform and how they can be beneficial for applications deployment across multiple environments.
When developing applications that are intended to be deployed across a range of environments (Development, Test, Production), developers often require different configuration and input parameters for their applications. Hard coding these parameters within application code is not good practice because the code would need to be changed when deploying the application to various environments. This results in tight coupling of the parameters and the objects that use those parameters, which is what we want to avoid. Environment variables are meant to tackle this scenario. Environment variables are key value pairs, which can be used as parameters across various applications in the Power Platform. By using environment variables, we can change our application parameters on-the-fly, without having to modify the application code. This becomes especially useful when deploying the application across multiple environments or when application lifecycle management (ALM) routines have been put in place.
So, how do we go about creating environment variables?
The following are the steps to create an environment variable:
- Go to https://make.powerapps.com/
- Select your environment of choice from the environment dropdown at the top right corner of the page
- Go to “solutions” tab
- Choose your desired solution
- Select “new” button at the top right corner of the page
- Select environment variable from the dropdown list
You can give your variable a display name of choice. The name (unique name) field will be automatically populated for you based on the display name. However, you can customize the name as well. You can add a description for your variable, but it is not required. Then you will have to choose a data type for your variable. You can choose from the following options:
- Decimal number
- JSON
- Text
- Yes / No
- Data Source
Once you are done with setting these fields, your form will look like the following:
The main benefit of environment variables is harnessed when applications utilizing environment variables are deployed across multiple environments. You can set different values for environment variables in each of your environments. This can be done when importing solutions containing environment variables into different environments. While importing a solution which contains any environment variable, you will have the option to provide a “current value” for respective variables, this is how you can set different values for your environment variables across multiple environments. You can also change values for environment variables in any environment by going to the solution(s) containing the respective variables and assigning new values to those variables.
Please note that environment variables can only be assigned new values while importing solutions into other environments when the exported solution containing the variable does not contain a “current value” for the variable. This can be done by going to the solution containing the variable, selecting the variable to open the environment variable form, then removing the variable’s “current value”, if any, from the solution. This removes the current value of the variable from the solution itself, but keeps the value stored in the current environment, so the variable can be continued to be used across multiple applications in the environment.
Learn more about Imperium's Power App Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.