Introduction
When building scalable and maintainable flows in Power Automate, dynamically retrieving metadata like the environment name, flow ID, and run ID becomes essential. This is especially useful when deploying flows across multiple environments or implementing logging and monitoring mechanisms. In this article, we’ll explore how to use built-in Power Automate expressions and functions to extract these details efficiently.
In addition, as a bonus tip in this article, I will suggest a standard Power Automate base template that you should use in each flow that you develop.
Getting the Environment Name: Power Automate does not directly expose the environment display name in the workflow() function. However, you can retrieve the environment ID using workflow().tags.environmentName
This will return the display name of the environment.
![Display name]()
Getting the Workflow Name or ID: You can retrieve the workflow name using workflow().name
This is useful for,
- Logging and notifications
- Conditional logic based on flow name
- Dynamic URLs for flow details
![Dynamic URLs]()
Getting the flow RUN ID: You can retrieve the flow RUN ID using workflow().run.name.
![RUN ID]()
Note. You can use the above expressions either in a variable or in a Compose action.
The above three variables or values are required to construct the flow RUN instance URL, which will help in troubleshooting in case of a flow error.
Creating the Flow Instance URL
Add a “Scope” action in Power Automate flow and rename it to Try.
Add a “Compose” action and concatenate all three variables.
- General form of a flow run URL.
- https://make.powerautomate.com/environments/', <environment-name>, '/flows/', <workflow-name>, '/runs/', <run-id>
- Use this expression in the Compose action to construct the flow RUN URL.
- concat('https://make.powerautomate.com/environments/', variables('varEnvtName'), '/flows/', variables('varFlowID'), '/runs/', variables('varRunID'))
![Compose action]()
Below is the screenshot of the complete flow using a Manual trigger.
![Manual trigger]()
Bonus Tip!
When creating a Power Automate flow, always include a Try and Catch scope. The image below shows the actions made in the Catch Scope, which you can use as the base or standard template for any of your flows.
Note. Catch Scope is executed based on the “Run After” settings of the Catch block. Click on the three dots (…) of the Catch scope and configure the run after settings as shown in the image below.
![Run After]()
Below are the actions used in the Catch Scope.
- Filter Array: use the result from Try.
![Filter Array]()
- Create an HTML table using the output from the Filter Array Action.
![HTML Table]()
- Send an email (v2): send the email to the required recipient in case of error, and use the below HTML in the Body of this action.
<style>
table {
width: 100%;
border-collapse: collapse;
font-family: Arial, sans-serif;
border: 2px solid #ccc;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
th,
td {
padding: 12px 15px;
text-align: left;
}
th {
background-color: #0078D4; /* Microsoft Blue */
color: white;
font-weight: bold;
border-bottom: 2px solid #005a9e;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
td {
border-bottom: 1px solid #ddd;
}
</style>
<p>
@{body('Create_HTML_table')}
</p>
<a href=@{concat(
'https://make.powerautomate.com/environments/',
workflow()?['tags']['environmentName'],
'/flows/',
workflow()?['name'],
'/runs/',
workflow()?['run']['name']
)}>
Check flow run
</a>
- Terminate: This action will end the flow with a failed status.
![Terminate]()
Below is the screenshot of the Catch Scope.
![Screenshot]()
Conclusion
By leveraging Power Automate workflow() function and strategic use of expressions, you can dynamically retrieve critical metadata to make your flows more robust, portable, and easier to manage. Whether you're deploying across environments or building advanced logging systems, these tips will help you streamline your automation efforts.