When building applications on the Power Platform, using development, test, user acceptance testing, and production environment is best practice. Therefore configuration settings or parameters or needed to move the application between those environments. Environment variables store particular application objects’ parameters and values and can be adjusted when moving a solution to another Power Platform environment. It could be problematic when using hard-coded parameter values in components of the application, especially when there’s a need to change the parameters during the application lifecycle management (ALM) progress.

On April 2021, Microsoft released the data source environment variables to general availability in the Power Platform 2021 release wave 1, which is for Power Automate flows. So let’s have a deeper look at the possibilities of those environment variables in a solution for a canvas app.

Benefits of using Environment Variables.

  • Replace parameter values while importing solutions to other environments.
  • Add configuration parameters for the data sources used in canvas apps and flows. For example, Store SharePoint Online site and list parameters as environment variables.
  • Manage the environments from a single place.
  • With-in different solution components, environment variables can be used, like a canvas app and flow.
  • Retiring a data source in production environments can be done by updating the environment variable to the new value without modifying the apps and flows. They will start using the latest data source values via the environment variable.
  • Supported by SolutionPackager and DevOps tools.
  • Environment variables can be collected in source control.

How do we define environment Variables in a solution? 

In a solution, we can add Environment variables. The following types are available:

  • Decimal number
  • JSON
  • Text
  • Yes/No
  • Data source

In this example, we will look at the data source.

New and select Environment variable.
New environment variable
  • Display name: Display name of the environment variable.
  • Name: Automatically generated unique name from the Display name (you can change it)
  • Description: Environment variable description.
  • Data Type. Select Data source

Select the data type: Data source.
We need to select a connector. We can choose only a SharePoint data source for now.

Select the connection and Parameter Type. When it’s the first parameter, select the first site.

Select the value for “Current site.”

Do the same for the SharePoint list, and select as parameter type “List.” The result will look something like this:

How do we make use of the Environment Variables in a canvas app? 

Defining and creating the environment variables is one point, and using them in a canvas app is a second. Let us have a closer look at how we can use those environment variables in a canvas application.

In the canvas app, adding a SharePoint data source will be the first starting point.

Add data source of SharePoint.
Select the advanced tab so that you can select the environment variable.

Select first the SharePoint site environment variable.

Idem for the SharePoint lists, select Advanced and select the lists needed in the canvas app and click “Connect.”

Adding a table and displaying the information of the events list gives us the result below.

A table displays data from the SharePoint list via the environment variable value.

How do we make use of the Environment Variables in a Power Automate Cloud flow? 

Same for Power Automate, creating a Power Automate flow that uses the environment variable is now possible and easy to integrate into the flow. In the SharePoint action, you need to select “custom” to choose the environment variable from the dynamic content.

Select the SharePoint site and list the variable.

When saving and running, the Power Automate results in an output of all items of the events list on the SharePoint site.

SUPPORT TIP

It could happen that the new environment variable values aren’t updating the data sources values in the canvas app. Resulting in connection errors: “The specific record was not found. Server responds: splist-events failed: list not found clientRequestid: [GUID] serviceRequestid: [GUID]”

This is normal bahavoir because the environment variable are not supported in Canvas Apps yet.

The current workaround is to remove the existing SharePoint connections in the canvas app and add them again the related connections vai the environment variables. At first import, the process will ask to assign the new environment variable values.

Requirements before moving the solution to the destination environment? 

Before moving the solution to the destination environment, we will need to do some preparation steps.
These are:

  • removing the current values of the environment variables out of the solution. 
  • publish all changes
  • running the solution checker to check for errors and warnings. 

So that during import of the “solution” into the destination environment, the process will notify you to select the new values for the connections and the environment variables. (during a manual execute import process) It results in new parameters for the SharePoint site and lists environment variables that will generate new data in the canvas app and flow. Let have a look at the steps in detail.

Export of the solution.

In this step, the current development environment variable values will be removed from this solution. Removing the current values will not impact the functionality of the canvas app or Power Automate flow in your development environment.

Remove current site value from the solution.
The current value has been removed.

Do this for all the environment variables in the solution and publish all changes and check for issues. If everything is positive, we can export the solution as a managed solution.

Import of the solution.

Select ZIP package and click next.

Select managed solution

Select existing connections or create new ones.

Select existing or create new connections.

Select the new values of the SharePoint site and lists and click import.

Playing the app will result that we will see the SharePoint event data of the new site.

Data DEV / Data PROD

Checking the result of the flow.

Result of the flow with the new environment variables values.

My conculsion!

As for a citizen developer using SharePoint as a data source, it is excellent to know that they can use environment variables to store the links of the SharePoint site and lists. This will help them move their application from their citizen DEV to a citizen PROD environment and just select the new connections and done.

Sometimes, the new values might be unavailable at the first import of the solution because Canvas app are not yet supported for environmental variables.

More ALM topics will follow soon, and if you like this blog. Please give me a dumbs up or share the blog. Thanks

Idea

Upvote the idea to add also Environment variables support for Canvas Apps.

2 comments

    1. Hello Kannan, Thanks for your feedback, and I hope you are doing great.
      No, the issue is that environment variables is only supported currently in Power Automate and not yet at the canvas app level. During my test, I was working, and after analysing the environmental values in the canvas app. It was pointing still to the old connection. I have created an idea. Please upvote and share it: https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Environment-Variable-support-in-Canvas-apps/idi-p/1360938
      I hope this helps.

      Kind Regards,

      Frederik Bisback

      Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: