Using PowerApps Environment Variables

If you paid close attention to the entities in your environments you might have noticed that environmentvariabledefinitions and environmentvariablevalues have recently showed up in all CDS environment databases (Dynamics 365 apps included). You can also look at your Solution History and probably see a solutions called EnvironmentVariables and EnvironmentVariablesAnchor. If you have EnvironmentVariables then you have the preview bits!

To use and see the Environment Variables as a component in the modern solution explorer you actually need to use the preview version of which is available at From there you should see it as a component you can create and add existing environment variables. New Component

When you create environment variables it is actually creating entity record data in the environmentvariablesdefinitions entity, if you add a value it adds to the environmentvariablesvalues entity related to the definition. You can only add 1 value per definition even though it is a 1:N relationship. The UI as well as plugins will block you from creating additional values.

How this data ends up in solutions is within the the customizations.xml with an <EnvironmentVariables></EnvironmentVariables> section and your values actually end up as environment_variable_values.json.


    <Definition IntroducedVersion="">
          <LocalizedName description="Testing Variable" languagecode="1033" />
          <LocalizedName description="This is a testing variable" languagecode="1033" />


  "EnvironmentVariableValues": [
      "EnvironmentVariableDefinition.SchemaName": "demo_TestingVariable",
      "Value": "newtestvalue"

So how do you go about using environment variables in your applications…It is just entity record data like any other entity, so you can query for it within plugins, canvas apps, flow, PCFs, etc. just as you would other entities. You will need to follow the logic pattern though of if value there is a value configured then use it if not then use default value found on the definition.

ALM Story with Environment Variables

Environment Variables are there to help solve the challenge of data that needs to be different for each environment, very much like a parameter. The most common pattern for this a DEV, TEST, PROD environment scenario but this is also going to be a very useful component for ISV based solutions where they deliver something that expects to talk to your version of that element and therefore you need to input your details.

For ISV patterns it is likely once installed in your environment you will go about creating a value for an existing environment variable. The value will override the default value found on the definition and away you go.

For the ALM pattern of DEV, TEST, PROD, etc. you probably want to manipulate the values as they are packaged into solutions. What is cool is you can use the existing Solution Packager Mapping to map your environment variables values file so that when you pack your solution you can pull the json file from another location and that location could be dependent on the environment you are working with therefore including the values for that environment.

Example solution packager mapping file for environment variables:

<?xml version="1.0" encoding="utf-8"?>
  <FileToFile map="EnvironmentVariables\environment_variable_values.json" to="..\mapfiles\environment_variable_values_dev.json" />

Example solution packager command with mapping file reference:

.\SolutionPackager.exe /action:Pack / /folder:'SolutionFolder' /packagetype:Unmanaged /map:'Solution-dev.mappings.xml'

PowerApps Build Tools for Azure DevOps Pipelines Pack and Unpack commands currently do not take a mapping argument but the Dynamics 365 Build Tools from Wael do! So if you wanted to use the mapping method of transformation on there then look at his tools currently.

You could also do this with other PowerShell commands to manipulate the JSON before it is packed if required. I would advise sticking with the Solution Packager Mapping though as that is supported by the SDK itself.

Check out the preview documentation for more details.

NOTE: There is an issue with solution packager currently where it won’t unpack environment variables. I would expect a fix or update to CoreTools will resolve this soon. Just needs to catch-up to the preview release.

You will need Core Assemblies SDK to ensure support for environment variables with solution packager.