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.
- Use an environment variable that you set during deployment
- 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.
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:
Operation: is equal to
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.
Then the respond to a Power app action will nbeed the following expression to get the name of the envrionmment:
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: