settings android tab

Power Platform Data source Environment Variables

Last year I wrote a blog about using dynamic SharePoint sites and lists in Power Automate. The information is still relevant for some scenario's. But earlier this year a new type of environment variables has been introduced which is a better approach to use in ALM scenarios of Power Platform solutions build on top of SharePoint.
Better yet: these environment variables also support ALM of Canvas Apps on SharePoint.

In this article I will explain how to work with Data source Environment Variables and share some tips and tricks.

Create Data source Environment Variables

Creation of Environment Variables takes place in the solutions section of an environment. Although Power Apps studio has a setting that allows for automatic creation of Data source environment variables, I prefer to create them myself and than use them in either Power Apps or Power Automate. That way you have control on the naming convention and can make sure the variable is part of the correct solution.

Environment variables are used to store environment specific configuration. For example a link to a website or an email address that should be different on your development or production environment.

Creating data source Environment Variables

To connect to SharePoint through Environment Variables you need to create at least 2 variables:

  • One to store a Site reference
  • One to store a List reference.

When creating the List reference variable, you need an existing Site variable, so start with creating the Site variable first.

  • Go to the Solutions section of your environment and select or create the solution you want the Environments variables to be part of.
  • Select Environment Variable from the New menu in the ribbon, add a meaningful name and description.
  • Make sure to select Data source as data type and select SharePoint as Connector
  • Select an existing SharePoint connection or create a new one and set the Parameter type to Site.

Finally you need to either add a Current site or Default site value. The Current site is a reference only meant for use in the current environment. The Default site value will be part of the Environment variable definition and exported with the solution to be used as fallback if a current value is missing. Either select a site from the dropdown or add a site URL manually. Don't forget to save it!

Repeat for the list variable – In this case selecting List as Parameter type. An Additional field Site will appear to allow you to link this variable to an existing Site type environment variable. Select the previously created Site environment variable from the dropdown.

Now let's use them in Power Apps and Power Automate.

Use in Power Automate

Not only the new data source environment variable type was introduced, but the way to use environment variables in Power Automate has also greatly improved. Before, you needed to locate the environment variable details in the corresponding Dataverse tables. But no longer! When creating a cloud flow in an environment that contains environment variables, available environment variables will be shown at the top of the list of dynamic content.

Because environment variables are environment scoped, they can also be used in the trigger of a cloud flow (unfortunatly not all connectors support this yet). In below example environment variables are used as site and list reference in the SharePoint trigger When an item is created. Instead of selecting a site and list, the option Enter custom value is chosen and the relevant environment variable is selected from the Dynamic content list.

When adding additional actions to the flow, the dynamic content from the trigger is based on the site and list set either as current or default value in the environment variables.

Use in Power Apps Canvas Apps

In Power Apps studio you can select the SharePoint connector the regular way. But instead of selecting a site directly from the list the environment variable can be chosen in the Advanced tab. The Choose a list section also has an Advanced tab where the List environment variable can be selected. The SharePoint data source will have the same display name as the List environment variable.

As mentioned before you can turn on automatic creation of data source environment variables in Power Apps studio. It is not my preferred way of working, but if you do, here is where to find the setting:

  • Go to App settings
  • Scroll down in the General section and switch on Automatically create environment variables when adding data sources.


Tips, Tricks & Gotchas

  • Did you know that the use of environment variables in Cloud Flows and Data source environment variables in Canvas Apps are a basic feature covered by all Power Apps and Power Automate licenses? Nice right!
  • Use of the other types of environment variables in Canvas Apps still relies on connecting directly to the Dataverse tables. In that case a premium license is needed. If you want to do that, the tables where the details are stored are:
    • Environment Variable Definitions – containing the schema name, data type and default value of all variables.
    • Environment Variable Values – containing available current values of the variables.
  • Environment variables are also part of the functionality of Dataverse for Teams. As long as your apps are consumed from within Teams all usage of environment variables is covered by the Teams license.
  • Environment variables are primarily meant for deployment purposes, but in Cloud Flows they are also an excellent way as reference for a site or list that are used in multiple actions.
  • If you want to manually update the current value of an environment variable that is part of a managed solution you can do that through updating it in the default solution.
  • If you manually update the current value of an environment variable this change is not pushed through to activated Cloud Flows. Turn them off and on again to make sure your change applies here as well.

For more gotchas check the list of current limitations in the Microsoft documentation.

Leave a Reply

%d bloggers like this: