| Mohsin Ahmed
In this blog, we are going to look at how we can use environment variables in Canvas Apps and how they can be useful in applications which are deployed across multiple environments. If you want to know more about environment variables and how they can be created in Power Platform, then go through the earlier blog in this series which covers that topic.
Throughout the blog, we will consider an environment variable “Debugging Enabled” already created in our environment. This variable is of type “Yes/No” and has a current value of “Yes”.
Now we will look at how we can access this environment variable from within a Canvas application.
Whenever we create environment variables, they are stored in two tables in Dataverse, namely “Environment Variable Definitions” and “Environment Variable Values". So firstly, we will have to access these tables in our Canvas application. We will do so by going through the following steps:
- Open Canvas application in edit mode
- Click on Data section in menu bar (left sidebar)
- Click on “Add Data” button
- Search for “environment”
- Add “Environment Variable Definitions” table
- Repeat steps 1 to 4
- Add “Environment Variable Values" table
We now have both tables included in our Canvas App.
The next step is to use these tables in any function in order to access the environment variable value. To do so, we will be using the “Lookup” function. For demonstration purposes, we will add a label control to the screen in which we can display the value returned by the environment variable.
The formula for accessing environment variables in code is:
LookUp('Environment Variable Values','Environment Variable Definition'.'Display Name' = "Debugging Enabled").Value
Where “Debugging Enabled” is the name of the environment variable used for demonstration. You will have to replace this name with the name of the environment variable you have created.
In this way, you can easily access environment variables in Canvas applications and ease application development across multiple Dataverse environments.
Join us next time, as we continue our journey of learning canvas apps.Click here to learn more about Imperium's Power Apps Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.