Home > CRM > Power Platform | Data source environment variables

Power Platform | Data source environment variables

Recently, I got a deployment (ALM) specific query from my SharePoint colleague who was exploring Power Platform’s Canvas Apps.

Query:

  • SharePoint team got 3 Sites (i.e., Dev/QA/Prod) and they also use 3 different Power Platform environments for Development, QA, and Production.
  • On Development environment, a Canvas App was built connecting to ‘Dev’ SharePoint site.
  • When the ‘Canvas App’ moved to QA and Production environments using Solution import, it must connect to the ‘QA’ and ‘Prod’ SharePoint sites.
  • Following diagram depicts the topology.

Solution:

  • It’s pretty a common scenario and one option would be post solution import to QA/Prod environments, reestablish the Connection reference manually. This option is time consuming and not intuitive.
  • Other recommended option is “Data source environment variables”. We will see the ‘How’ part in next section.

Data source environment variables:

  • As we know, Environment variables store the parameter keys and values, which then serve as input to various other application objects.
  • Environment variables are now much simpler to work with and can store parameters required to connect to data.

In this article, lets see how to create and consume Data source environment variables in Canvas App.

Configure Data source environment variables:

Create Environment variables:

In this article, I am using SharePoint site to connect from Canvas App.

  • Create a SharePoint site if not exists already and add a list using native ‘Issue Tracker’ template (You can also use any List of your choice).
  • From Power Apps maker portal, connect to Dev environment and create a new solution.
  • Create a new ‘Canvas App’ from the Solution.
  • Now, from Canvas App, go to ‘File-> Settings’, enable the setting to Automatically create environment variables when adding data sources.
  • Add a SharePoint data source and configure the Site and List.
  • Once you add the ‘SharePoint’ data source, you would notice a banner message, indicates Environment Variables were auto created.
  • Click on the ‘Manage them here’ will redirect you to the Solution where you can access the auto created ‘Environment Variables’.
  • That’s all needed to create Environment Variables.

Configure Environment variables during Solution Export and Import:
Exporting Solution:
  • Before exporting the solution, select one of the Environment variables and choose ‘Edit’ and select ‘Remove from this solution’.
    • This is step is important. You will not be prompted for new values during solution import if the environment variables already have either a default value or value present, if not chosen the ‘Remove from this solution‘.
  • Repeat this step for other Environment variables.
  • Export the solution.
Importing Solution:
  • Select the target environment (I.e., QA in my case) and choose import the Solution.
  • You will get following ‘Connections’ pane which will allow you to configure to the QA SharePoint site.
  • You will be redirected Connections screen to establish connection to QA SharePoint site. Once you establish connection, it looks as below.
  • Go back to Solution import process and map the new connection configured in above step.
  • In the next step of import, system will ask you to provide values for the Environment variables (i.e., Site, List).
  • You would not get above Connection reference and Environment Variables panes, if you have not chosen the ‘Remove from this solution‘ option.

This approach eliminates manual step of reestablishing connection post solution import to Target environment.

Important Points:

  • ‘Data Source Environment’ variables doesn’t require querying environment variables via Dataverse connector or require premium licenses.
  • The Environment variables can be unpacked and stored in source control using DevOps Power Platform tools.
  • We can also use ‘Pre-existing’ data source Environment variables by creating a new ‘Environment Variables’ of ‘Data Type’ of ‘Data source’.
    • Use this option, if you don’t want auto creation of Environment Variables (i.e., By enabling the setting to Automatically create environment variables when adding data sources).

Refer docs for more details.

🙂

Categories: CRM
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: