Display the environment name in your Canvas App in Power Apps

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
Display the environment name in your Canvas App in Power Apps 1

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
Display the environment name in your Canvas App in Power Apps 2

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
Display the environment name in your Canvas App in Power Apps 3

Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. You can contact me using contact@sharepains.com

Related Posts

2 thoughts on “Display the environment name in your Canvas App in Power Apps

  1. Properties n’existe pas, c’est directement displayname qu’il faut écrire !
    Il faut tester avant d’écrire des anêries …

Leave a Reply

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

Discover more from SharePains

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

Continue reading