Get Flow Run ID, Flow ID and Environment ID in Power Automate Dynamically

Power Automate: Get Flow Run ID Dynamically in 2 Ways

No comments

Loading

In this article, we will learn how to get flow run IDs using Power Automate dynamically from the flow run history URL. While we learn about getting flow run IDs, we will also learn how to get flow IDs and environment IDs from the flow run history URL. Before getting into the article demo, let’s understand: What is Environment in Power Automate?, What is Flow ID in Power Automate?, and What is Flow Run ID in Power Automate?

What is Environment in Power Automate?

In the context of Power Automate, “environment” refers to a logical container that helps you manage and organize your Power Automate flows, business process flows, and other resources. The Power Platform Environments provide a way to group and isolate your flows, making it easier to control access, permissions, and deployment of these resources within Microsoft Power Automate.

Key points about environments in Power Automate:

  • Isolation: Environments allow you to isolate your flows and related resources from each other. This is particularly useful in larger organizations where different departments or teams might be using Power Automate for various purposes. Each environment can have its own set of flows, connections, and settings.
  • Security and Access Control: You can control who has access to specific environments. This helps ensure that only authorized individuals can work with the flows and data within a given environment. You can define user roles and permissions for each environment.
  • Resource Management: Environments help you manage resources like connections, gateways, and custom connectors. You can have dedicated connections for specific environments, which is crucial for maintaining security and compliance.
  • Deployment and Versioning: Environments facilitate the deployment of flows and other resources. You can develop and test flows in one environment and then promote them to a production environment when they are ready. This separation makes it easier to maintain different versions of flows.
  • Shared Resources: Some resources, like custom connectors and gateways, can be shared across multiple environments, allowing for reuse and consistency.
  • Default Environment: Each user in Power Automate has a default environment, which is created automatically. This environment cannot be deleted and is used for flows that are not specifically assigned to other environments.

What is Flow ID in Power Automate?

In Power Automate (formerly known as Microsoft Flow), a “Flow ID” refers to a unique identifier assigned to each individual flow that you create within the Power Automate platform. The Flow ID is a string of characters or numbers that distinguishes one flow from another. It serves several important purposes:

  • Identification: The Flow ID is used to uniquely identify a specific flow within your Power Automate environment. This is particularly useful when you have numerous flows and need to reference or manage them.
  • Referencing Flows: When you work with Power Automate through the user interface, APIs, or PowerShell scripts, you often need to reference a specific flow. You can use the Flow ID to do so, ensuring that you are targeting the correct flow.
  • Logging and Monitoring: Flow IDs are used in logging and monitoring systems to track the execution and history of individual flows. This helps with troubleshooting, auditing, and performance analysis.
  • Integration with Other Services: When integrating Power Automate with other services or applications, the Flow ID may be required to trigger or interact with a specific flow programmatically.

The Flow ID is typically a long alphanumeric string that is not intended to be user-friendly but serves as a unique identifier behind the scenes. It’s used by administrators, developers, and automation experts to manage and maintain the flows in Power Automate.

You can typically find the Flow ID associated with a specific flow in the Power Automate interface or when working with the Power Automate API. It’s an important reference for tracking and managing your automated workflows.

What is Flow Run ID in Power Automate?

In Power Automate (formerly known as Microsoft Flow), a “Flow Run ID” refers to a unique identifier that is assigned to each instance of a flow when it is executed or triggered. It is used to uniquely identify and track a specific run or execution of a flow. Flow Run IDs are particularly important for monitoring, troubleshooting, and auditing the execution of your automated workflows. Here’s how they are used:

  • Unique Identification: Each time a flow is triggered, whether manually by a user, on a schedule, or in response to an event, a new Flow Run ID is generated. This ID is unique to that particular execution of the flow.
  • Logging and Monitoring: Flow Run IDs are used in logs and monitoring systems to track the history and details of a flow’s execution. This allows you to see when a flow was run, whether it succeeded or encountered errors, and the specific data associated with that run.
  • Troubleshooting: When a flow run encounters issues or errors, the Flow Run ID is useful for troubleshooting. It can help you pinpoint the exact run that had problems, making it easier to diagnose and resolve issues.
  • Auditing and Compliance: Flow Run IDs are important for auditing and compliance purposes. They allow organizations to maintain records of which flows were run, when they were run, and the data processed during each run. This can be crucial for regulatory compliance and security audits.
  • Run History Version Control: Each flow’s run history maintains its own unique run ID, which helps in analyzing the flow if you encounter issues.

Flow Run IDs are typically represented as long alphanumeric strings and are not meant to be user-friendly but serve as unique identifiers for tracking and managing flow executions. You can access Flow Run IDs in the Power Automate interface and retrieve them through the Power Automate API or related monitoring and reporting tools.

Demo: Get Flow Run ID in Power Automate

In this section, we will learn how to get a flow run ID using the Power Automate out-of-the box tool, and then we will learn how to get a flow run ID using the Power Automate flow.

Approach 1: Using the Out of the Box Tool Flow Run History in Power Automate

Login to your Power Automate environment.

Click on the “My Flows” link from the left-side panel.

Select the flow for which you want to see the run history.

Step to get flow run history in Power Automate
Step to get flow run history in Power Automate

Click on the “Run history” menu.

Then, we will get into the flow run history screen.

Flow Run History in Power Automate
Flow Run History in Power Automate

On the flow run history page, we can see the last 28 days of run stances for the selected flow, and each flow has its own run id, which is a combination of alpha-numeric text. It occurs at the last of the flow run URLs, as shown above, the highlighted one.

If we navigate this flow-run URL, we will get into this URL:

https://make.powerautomate.com/environments/Default-f10e1e03-fffa-47d0-86f4-d0e3c317c65d/flows/63351b1a-b72c-4abe-b0b8-023f60ad9e2b/runs/08585044383120505650595133849CU55

From this URL, we go the below flow run ID:

08585044383120505650595133849CU55

By now, we have learned about how to get a flow run ID using the Power Automate Run History menu feature. Now, let’s move on to how to get flow run IDs using the Power Automate flow dynamically.

Approach 2: Get Flow Run ID using Power Automate Flow Dynamically

Let’s have a look at the below image, where we can see the environment ID, flow ID, and flow run ID.

In this demo, we will extract each substring, like environment ID, flow ID, and flow run ID, dynamically from this flow run history URL.

Environment ID, Flow ID and Flow Run ID in Power Automate
Environment ID, Flow ID and Flow Run ID in Power Automate

In this section, we will learn how to get flow run ID using the Power Automate flow dynamically.

Create a manually triggered Power Automate flow.

Add an initialize string-type variable action to your flow.

In the value section, assign your flow-run URL.

Initialize string type variable in Power Automate
Initialize string type variable in Power Automate

Then, add a compose data operation action, and assign the below substring expression:

substring(variables('varStrFlowRunURL'),add(lastIndexOf(variables('varStrFlowRunURL'),'/'),1))
Extract flow run id from flow run history using substring function
Extract flow run id from flow run history using substring function

Explanation:

In the above Power Automate substring function, we have used the lastindexOf function to get the last position of the forward slash (“/“), then added number 1 to it, to get the substring after the last index of the forward slash (“/“), which is nothing but the flow run ID.

Output:

08585044383120505650595133849CU55
Extract flow run id from flow run history using substring function - demo
Extract flow run id from flow run history using substring function – demo

Demo: Get Flow ID in Power Automate

Considering the above flow run URL, we will now extract the flow ID from the given flow run URL.

Add two compose actions to get the position of the “/flows/’ and “/runs/” substrings, and pass the below two “nthIndexOf” Power Automate functions:

Compose – Get From source index (Flows index)

nthIndexOf(variables('varStrFlowRunURL'),'/flows/',1)

Compose – Get To target index (Runs index)

nthindexOf(variables('varStrFlowRunURL'), '/runs/',1)

Extract substring position using the Power Automate nthIndexOf and indexOf function

Extract substring position using the Power Automate nthIndexOf and indexOf function

 

Note:

  • In the above example, we have used the nthIndexOf Power Automate function, where we can use the normal indexof Power Automate function as well. To show how the nthIndexOf function works in Power Automate, we have used the nthIndexOf function.

Then, find the length between the target and source substring positions using the below sub() function expression:

Length between To and From Index: Example of sub function in Power Automate

sub(outputs('Compose_-_Get_To_target_index_(Runs_index)'),outputs('Compose_-_Get_From_source_index_(Flows_index)'))
Example of sub function in Power Automate
Example of sub function in Power Automate

Now, we got the source and target substring length position to extract the flow id from the given flow run URL.

Get Flow ID from the Flow Run URL in Power Automate substring function

To get the flow ID from the flow run URL, we can use the below substring function expression:

substring(variables('varStrFlowRunURL'),add(outputs('Compose_-_Get_From_source_index_(Flows_index)'),7),sub(outputs('Compose_-_Difference_in_To_and_From_Index_(Between_Runs_and_Flows)'),7))

Get Flow ID from the Flow Run URL in Power Automate substring function

Get Flow ID from the Flow Run URL in Power Automate substring function

Note:

  • In the above substring function example, you may notice that we have used the add function, where we have added 7 to the source index (‘/flows/‘). This will start the index position after the ‘/flows/’ position. And we have used the sub function to substract 7 from the length between the target and source index positions; this will substract the ‘/runs/‘ from the substring. So, we will get the desired flow ID as an output.

Now, let’s run the flow.

Output: Flow ID

63351b1a-b72c-4abe-b0b8-023f60ad9e2b
Get Flow ID from the Flow Run URL in Power Automate substring function - demo
Get Flow ID from the Flow Run URL in Power Automate substring function – demo

Demo: Get Environment ID in Power Automate

Considering the above flow run URL, we will now extract the Environment ID from the given flow run URL. It is same logic as getting flow ID.

Add two compose actions to get the position of the “/environments/‘ and “/flows/” substrings, and pass the below two “nthIndexOf” Power Automate functions:

Compose – Get From source index (Environments index)

nthIndexOf(variables('varStrFlowRunURL'), '/environments/', 1)

Compose – Get To target index (Flows index)

nthindexOf(variables('varStrFlowRunURL'), '/flows/', 1)
Get Environment ID from the Flow Run URL in Power Automate
Get Environment ID from the Flow Run URL in Power Automate

Length between To and From Index (‘/flows/’ and ‘/environments/’)

To find the Length between To and From Index (‘/flows/’ and ‘/environments/’), we can use the below sub function expression:

sub(outputs('Compose_-_Get_To_target_index_(Flows_index)'),outputs('Compose_-_Get_From_source_index_(Environments_index)'))
Length between To and From Index in Power Automate
Length between To and From Index in Power Automate

Get Environment ID from the Flow Run URL in Power Automate substring function

To get the environment ID from the Flow Run URL in Power Automate, we can use the below substring function:

substring(variables('varStrFlowRunURL'), add(outputs('Compose_-_Get_From_source_index_(Environments_index)'), 14), add(outputs('Compose_-_Difference_in_To_and_From_Index_(Between_Runs_and_Flows)'),1))
Get Environment ID from the Flow Run URL in Power Automate substring function
Get Environment ID from the Flow Run URL in Power Automate substring function

Note:

  • In the above substring function example, you may notice that we have used the add function, where we have added 14 to the source index (‘/environments/‘). This will start the index position after the ‘/environments/‘ position. And we have used another add function to add 1 to the length between the target and source index positions; this will extract the substring before the ‘/flows/‘ position. So, we will get the desired environment ID as an output.

Now let’s run this flow.

Output:

Default-f10e1e03-fffa-47d0-86f4-d0e3c317c65d
Get Environment ID from the Flow Run URL in Power Automate substring function - demo
Get Environment ID from the Flow Run URL in Power Automate substring function – demo

Summary: Get Flow Run ID, Get Flow ID, and Get Environment ID in Power Automation

Thus, in this article, we have learned about how to get flow run ID, flow ID, and environment ID in Power Automate. These IDs will help you while you work on the larger complex flow for your flow troubleshooting.

See Also: Power Platform Articles

You may also visit the Power Platform article hub, where you will see a bunch of articles focusing on Power Platform, like Power Automate, Power Apps, etc. All the articles are written with real-time project scenarios and troubleshooting techniques. For the Power Automate function references, you may refer to this Microsoft Power Automate Function references  article.

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment