DevOps in Power Platform. Environment variable for configuration details using Solution.

Introduction:

In any application development world, we have a concept called as environment variable where we store configuration details like API prefixes (base url), environment name, rather anything that is going get changed for every environment.

Usually any enterprise operates (develops, tests and releases) their systems in the following environments and in the same order:

· Development (Dev)

· SIT (System integration test)

· UAT (User acceptance Test)

· Prod (Production)

For these environments, security groups would be different, API prefixes would be different and many other things too.

To substitute these values in an environment specific manner is a challenge if environment variable is not used.

In this article, we will see how to incorporate environment variable and its application in power platform.

Prerequisite:

We are going to use Solution to package our components into a single file. To use a solution, you need Common data service in your connection reference. So, make sure you have the necessary PowerApps plan (Community edition would work).

What is a Solution?

For newbies, Solution is file where you can add all the power platform components that belong to the same application and store them as a single zipped file.

Primarily its used to ship applications from one environment to other.

We are going to follow the below steps:

1) Create a solution

2) Inside the solution, create a component of type Environment Variable. Name it and include a default value.

3) Create a Power Automate flow, to fetch the environment variable.

4) In the same flow add an action to call an HTTP GET method using api prefix url field from our default value in environment variable.

Action:

Step1:

Go to make.powerapps.com and login with your Microsoft account and then click on Solutions tab in the left side menu:

Step2:

Create a solution say TestSolution:

Here Publisher refers to the person creating the solution. You can create a publisher for yourself or your organization. For now, I just went with what CDS provides me, which is default CDS publisher.

Step3:
Once inside the solution, Click on New and add an Environment Variable:

Enter all the details for your environment variable like name, description, type of variable (ours will be a JSON) and include a default value:

I am using jsonplaceholder APIs which are publicly available for use. I have created a JSON file which looks like this:

{

“environment”:”DEV”,

“apiPrefix”: “https://jsonplaceholder.typicode.com”

}

– First field is environment name, which is dev. I can use this and display in PowerApps so users know which environment they are in.

– The API I am using is a GET call and looks like https://jsonplaceholder.typicode.com/comments. Here /comments is the path and https://jsonplaceholder.typicode.com is the API prefix base url. This base url will be different for different environments. For eg:
https://devjsonplaceholder.typicode.com for dev

– https://sitjsonplaceholder.typicode.com for sit

– https://uatjsonplaceholder.typicode.com for uat

– https://jsonplaceholder.typicode.com prod

So, without hardcoding, we can use different API URLs for different environments.

In the snapshot below config component of type Environment variable is created and has a name of crc54_config (this is the publisher value assigned by cds as a default value):

Step4:

Now click on New -> Flow.
We will now create a Power Automate flow to fetch the environment variable details. From there you can pass the values to PowerApps or do anything you want with them:

When you click on flow, it takes you to the Power Automate site (flow.microsoft.com) editor, where you can create flows:

Here follow the steps as mentioned:

– Create an action to manually trigger a flow.

– Then create an action to initialize a variable and name it config of type string.

  • Then create an action to fetch the environment variable details using List Records action of CDS:

– In Entity name select Environment Variable Definition, this tells CDS to find a component of type environment variable.

– To help CDS further, using filter query and mention the publisher name as

schemename eq ‘crc54_config’. This tells CDS to find an environment of publisher name crc54_config.

  • Then create an action to capture the values for which you need Set Variable action and using Dynamic content, use Default Value to the set variable:

Now you have your environment variable details in a variable called config of type string.

  • Parse this string to get the individual fields. Use the Parse JSON action and take config variable as input:
  • Now Use HTTP action to call the GET API and fetch the results. Since config is now parsed you can use the fields from dynamic content:
  • Pass /comments as path and use apiPrefix field as base url.
  • When Flow is tested it will fetch you an array of objects:

NOTE: Currently I am using the community trial plan of Powerapps where I have created an environment to play around called Rahul Sharma’s environment:

When you create multiple environments, like the below:

You can use the method I have provided to fetch environment specific details.

I have implemented a much cleaner way of the above. Please reach me at my email ID for more info
rahul1406@gmail.com

Hope this helps.

Thank You!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *