Get the current environment of an app 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
Get the current environment of an app in Power Apps 1

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
Get the current environment of an app in Power Apps 2

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
Get the current environment of an app in Power Apps 3

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
Get the current environment of an app in Power Apps 4

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
Get the current environment of an app in Power Apps 5

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


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

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