Announcing data source environment variables

Today we’re excited to announce a vast new set of capabilities that provide enterprise grade application lifecycle management for the data sources that canvas apps and cloud flows connect to. Environment variables are now natively built into authoring experiences across canvas apps and cloud flows as well as solution authoring and solution import experiences. We’ve also added several new and enhanced API’s to simplify working with environment variables in code and within automated ALM pipelines.

Data source environment variables gif

 

 

Why data source environment variables?

Environment variables have been a powerful tool for a variety of ALM scenarios as they allow you to externalize input parameters from the components that use them. They’re now much simpler to work with and can store parameters required to connect to data.  This allows you to change the data sources (as well as other types of parameters) when migrating solutions to other environments.

Build

  • Environment variables are automatically created to store data source parameters when connecting to data within canvas apps. *Limited set of connectors. Refer to docs for the latest information
  • Reuse the same environment variables across canvas apps, flows, and other components
  • Natively insert any type of environment variable in triggers and actions within cloud flows. *Limited set of connectors for trigger support
  • Doesn’t require querying environment variables via Dataverse connector or require premium licenses like before

Deploy & Automate

  • Provide new values when importing solutions in a user friendly UI
  • Various new API’s and API enhancements dramatically simplify programmatic interactions. We use the same API’s internally and now customers can use them! *API’s are live. Docs are in the process of being published
  • Change values in build pipelines and source control
  • New build tasks will be available soon for working with connection references and environment variables
  • New ALM Accelerator will be available soon to package the use of these assets & allow customers to quickly get started with automated ALM

Govern

  • Gives admins more control and visibility over data sources used in apps and flows
  • Admins can retire and replace a production data source without modification to the apps and flows

Let’s use a simple example:

  • I use different Power Platform environments for development, QA, and Production
  • In the development environment I build a canvas app and flow that connect to a development SharePoint site and list
    • Similarly, I have different SharePoint sites and lists for dev, QA, prod
  • When I migrate the solution containing the apps and flows to QA and Production environments they must connect to the corresponding QA and Production SharePoint lists

Step 1: Create my solution and canvas app

  1. Login to Power Apps or Power Automate
  2. Create a new solution
  3. Create a canvas app from the solution
  4. In the canvas app designer enable the setting to Automatically create environment variables when adding data sources
    1. This step is optional if following the approach in 7a
  5. Add a data source for SharePoint and select a site, then one or more lists as you ordinarily would.
  6. Now you’ll see a confirmation screen to notify you that environment variables will be created
    1. Note: data source environment variables can also be created within the solution interface. You can select pre-existing environment variables when adding a data source to your app by clicking the “Advanced” tab
  7. When you save the data source your app is now connected to SharePoint via two related environment variables. One to hold the site URL and one to hold the list ID (dataset and table parameters)

 

Step 2: Create a cloud flow

  1. Add a button to your app
  2. For the action select Power Automate, then Create a new flow
  3. Set the trigger
  4. Choose an action for SharePoint. I’ll use Create item for this example.
  5. In the Site address parameter, scroll down and click Enter custom value
  6. Under Dynamic content you’ll see a list of environment variables to choose from
  7. Select the appropriate site environment variable created when building the canvas app in step 1
  8. Do the same for List name, then save the flow
  9. Your flow is now connected to the same SharePoint site and list and using the same environment variables as your app


Note: Some experience improvements are rolling out and some are still in-development. For example, the “Parameters” label will soon be “Environment variables” and the list will have better filtering based on the parameter type. 

Step 3: Migrate your solution to another environment

If you want to provide new environment variable values when importing to other environments, it’s important to remove the values from your solution before it’s exported. You do not need to delete them from the environment, however. This way everything will remain connected in the development environment. 

  1. Select the SharePoint site environment variable in your solution. In the edit panel, select the ellipsis by Current site, then Remove from this solution
  2. Do the same for the SharePoint list environment variable
  3. Export the solution as managed
  4. Switch to a different environment, then import the solution
  5. You’ll be prompted to select a SharePoint connection (for the connection reference), then can proceed to provide new values for the environment variables
  6. Import the solution and everything will be connected to the new SharePoint site and list. No need to modify or turn on anything!

Step 4: Manage

It’s important to ensure users of the application have appropriate access. In addition to sharing the apps and flows, they’ll need an appropriate security role granting access to canvas apps, processes, and environment variables in Dataverse.

If you need to change the data sources being used in a production environment, you may edit the values of the environment variables or update them via managed solution upgrade. Any apps and flows using the environment variables will start using the new values.

More information

For more information please refer to the docs.

In case you’re unfamiliar with importing solutions, connection references, and environment variables I suggest reading this blog post to gain a base understanding. 
We’d love to hear your feedback. Please comment below or visit the Power Apps community site.