Display the environment name in your Canvas App in Power Apps Microsoft Office 365 image 119

So you start using environments and you deploy the app across multiple environment. How do users know which environment they are in?

Get the environment name

There are two easy options to get the environment name while running an app.

  1. Use an environment variable that you set during deployment
  2. Create a flow that finds the environment name

The first option is easy, just set a text environment variable to the right value and your done. But this is something that needs to be done and could potentially go wrong if you forget to set the environment name.

Create a flow to get the environment name

The flow that we need to create has just 4 steps.

As we will be calling this flow form an app, there will be the Power Apps trigger. You can use either version 1 or version 2.

Display the environment name in your Canvas App in Power Apps Microsoft Office 365 image 117

Then we will use the List My Environment step. This step will get all the environment details in your tenant.

As there are no filter options on the Get my environment action, we will need to use a Filter Array action to get the current environment.

Filter the current environment

We will need a couple of expressions here:

From: outputs(‘List_My_Environments’)?[‘body/value’]

Left: item()[‘name’]

Operation: is equal to

Right: workflow().tags.environmentName

The above details will take the list of environments and return just the one environment that is recognised by the workflow function as the current environment.

Display the environment name in your Canvas App in Power Apps Microsoft Office 365 image 118

Then the respond to a Power app action will nbeed the following expression to get the name of the envrionmment:

first(body('Filter_array')).properties.displayName

We now haver the name of the environment as a simple text ready to be returned to the app.

Display the environment name in the app

All we now have to do is update the app to show us the display name of the environment:

@first(body('Filter_array')).properties.displayName
Display the environment name in your Canvas App in Power Apps
Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

Leave a Reply

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

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading