Environment variables overview

Apps and flows often require different configuration settings across environments. Environment variables as configurable input parameters allow management of data separately compared to hard-coding values within your customization or using additional tools. Because they're solution components, performance is much better than importing configuration data as record data.

Benefits of using environment variables:

  • No need to manually edit configurable values in a production environment.
  • Configure one or more variables in one place and reference like a parameter across multiple solution components.
  • Enter different values while importing solutions to other environments.
  • Update values without a code change.
  • Granular level security managed by Common Data Service.
  • Unlimited number of variables (max solution size is 29 MB).
  • Service the definitions and the values independently or together.
  • Supported by SolutionPackager and DevOps tools enable continuous integration and continuous delivery (CI/CD).
  • Support for localization.
  • Can be used to control feature flags and other application settings.

How do they work?

Environment variables can be created and managed through the modern solution interface or by using code. A separate JSON file is created within your solution package for the values, which can also be managed in source control and modified in a build pipeline. Export to and import from Excel is supported. After creating environment variables, you can use them as inputs within plug-ins, flows, and other components.

Create an environment variable in Power Apps

  1. Sign in to Power Apps, and then on the left panes select Solutions.
  2. On the command bar, select New and then select Environment variable.
  3. On the left pane, complete the following fields, and then select Save:
    • Display name. Enter a name for the environment variable.

    • Name. The unique name is automatically generated from the Display name, but you can change it.

    • Data Type. Select from Decimal number, Text, JSON, or a Two option field.

    • Default Value. This field is part of the environment variable definition entity and is not required. Set a default value for the production environments or when the values don't need to be changed for different environments.

    • Current Value. Also known as the override value. This field is optional and is a part of the environment variable value entity. Set the value when you'd like to override the default value in your current environment. Remove the value from your solution if you don't want to use it in the next environment. The values are also separated into a separate JSON file within the solution.zip file that is exported.

      Separation of default value and current value allows you to service the definition and the default value separately from the current value. It also allows us to extend the functionality in the future to support multiple values scoped to a specific run time context.

      New environment variable

      Note

      A value can't exist without a definition. The interface only allows creation of one value per definition.

Enter new values while importing solutions

The modern solution import interface includes the ability to enter values for environment variables. This sets the value property on the environmentvariablevalue entity.

You will not be prompted if the environment variables already have either a default value or value present; whether values are part of your solution or are already present in Common Data Service.

Note

You may remove the value from your solution before exporting the solution. This ensures the existing value will remain in your development environment, but not get exported in the solution. This approach allows a new value to be set while importing the solution into other environments.

Notifications

A notification is displayed when the environment variables do not have any values. This is a reminder to set the values so that components dependent on variables do not fail. It also allows partners to ship variables without values and the customer is prompted to input the values.

Note

We recommend partners build their own interfaces requiring the customers to provide the values. Notifications help prevent failures if this step is skipped. 

Security

Both the environmentvariabledefinition and environmentvariablevalue entities are user or team owned. When creating an application that uses environment variables, be sure to assign users the appropriate level of permission. More information: Security in Common Data Service.

Current limitations

  • Caching. Plugins will need to run a query to fetch the values.
  • Canvas apps and flows can consume environment variables just like entity record data.
  • Azure Key Vault integration for secret management. Currently environment variables should'nt be used to store secure data such as passwords and keys.
  • Data types are validated in the modern solution interface only, but not currently on the server during the preview.
  • Dependencies are not enforced for certain component types.
  • If using Excel to import environment variables, be sure to pre-pend the publisher prefix to the SchemaName.

See also

Power Apps Blog: Environment variables available in preview! Use plug-ins to extend business processes
Web API samples
Create Canvas app from scratch using Common Data Service.
Create a flow with Common Data Service