“I have so many environment variables to keep the flow / environment information, can I somehow get it directly in the Power Automate flow?”
When building a flow there’re some situations where you might need the environment / flow / run information. It can be to send an error message when the flow fails, automated restart of expired flows, backup flows, or if you want the flow to behave differently on DEV and PROD environments.
One way to get those are environment variables, but that’s something you must update manually on each environment. And manual update always brings the risk of setting it wrong, not to mention it might lead to a ton of variables on the environment. Is there a better way? To get it directly from the flow, to have always the right value?
Get the information with the workflow() expression
You can get most of the information using the workflow() expression. This expression will give you among others the environment id, workflow id, workflow name, and run id. It doesn’t have any parameters and the output might look as below:

Use an expression to get these values from the output JSON.
Environment id:
workflow()?['tags']['environmentName']
Flow id:
workflow()?['name']
Flow name:
workflow()?['tags']['flowDisplayName']
Run id:
workflow()?['run']['name']
These expressions can be used in any action to keep the right value for given environment, e.g. to resubmit a flow.

No hard coded values, no environment variables, you’ll get everything you need directly from the flow.
Get the environment name too
One piece of information you might be missing is the environment name. Unfortunately, you don’t get that with the workflow() expression, you’ll need another action.
Add the ‘List my Environments’ action from the ‘Power Automate Management’ group.

It’ll give you all your environments, including some useful details, among them the environment display name.

Add ‘Filter array’ to get only the current environment using its ID…

…and extract the environment name with another expression.
first(body('Filter_array'))?['properties']?['displayName']

Summary
When building a flow you should avoid hard coding any values as much as possible. Environment variables are a good solution, but there’s a better one still – get it directly from the flow. As shown in this article, it’s very easy to get information about a Power Automate flow. You can get lots of information directly with the workflow() expression, and the rest if you use this expression to gather it from other sources.
1 thought on “How to get Power Automate flow information directly in the flow run”