Get the current environment displayed in Power Apps.

Today I tried to display the current environment in a canvas app in Power Apps. This was slightly harder than expected.

Power Platform connectors

there are quite a few Power Platform connectors that I hoped to use. Just to name a few Power Apps for Makers, Power Apps for Admin and even Power Platform for Admins. But none of these gave me the option to get the current environment’s name

So I had to make an escape into Power Automate. No not the connectors, I had to create a speedy flow!

Get the current environment Id

So the flow will just use the following expression to get its own environment ID using the dot-syntax rather than the ? syntax:

workflow().tags.environmentName
Get the current environment flow

Then the flow will return the output from my compose action back to the flow.

Get the current environment of an app in Power Apps Microsoft Office 365 image 49

Now all I have to do is to create a button and display the environment in my app.

Get the current environment of an app in Power Apps Microsoft Office 365 Button Calling flow to get environment

The code to display the environment is a simple concatenation of texts. But this is not really that nice. We want the environment name. We could of course have collected the name within the flow, but you might want to use the environment id for other things too.

Get the current environment of an app in Power Apps Microsoft Office 365 Environment guid returned

Ok, so that GUID is not very nice.

Get the current environment name

A small change tot he Button’s code will resolve this issue. The flow is still called by the app and the environment Id is collected. Then the Is is used within the PowerPlatformforAdmins connector to get all the details for a single environment.

Set(varEnvironmentID, GetEnvironment.Run().result);

Set( varEnvironment, PowerPlatformforAdmins.GetSingleEnvironment(varEnvironmentID).properties.displayName)
Get the current environment of an app in Power Apps Microsoft Office 365 image 50

And now we have the environment name displayed in the app.

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