Quickly Monitor Long Running Power Automate Flows from an Environment

Quickly Monitor Long Running Power Automate Flows from an Environment

No comments

Loading

In this “Monitor Long Running Power Automate Flows or Get Long Running Flows” article, we will learn about how to get all long running Power Automate flows from a given Power Platform environment quickly without the manual efforts. This will streamline your flow management process to the pro level; you don’t need to put in your manual efforts to look around about the Power Platform environment; instead, you can leverage your productive time for other priority tasks. In other words, we can say that this approach revolutionizes your flow management, saving you from the manual task of searching. You can now redirect your valuable time to other high-priority activities while maintaining a professional flow management process.

In the dynamic realm of the Power Platform, effective workflow management is pivotal to ensure the smooth functioning of various business processes. However, as the number of flows within a Power Platform environment grows, so does the complexity of monitoring and managing them. Manual monitoring by environment administrators can become overwhelming, especially when dealing with flows that run for extended periods due to technical glitches.

Understand the business behind Long Running Flows in Power Platform Environment

Let’s understand the below concepts with respect to long-running flows in the Power Automate environment:

The Challenge: Long-Running Flows and Resource Drain

In many Power Platform environments, a multitude of flows is commonplace, each serving a crucial function. However, some flows may encounter technical issues, causing them to remain in a running state for an extended duration. This delay impacts business transactions, potentially leading to inefficiencies. Moreover, prolonged running flows consume substantial resources, affecting the performance of other objects within the Microsoft 365 ecosystem.

A Proactive Solution: Automated Flow Monitoring and Management(Get Long Running Flows)

To address this challenge, I devised a proactive approach leveraging Power Automate. I developed a custom flow designed to scan all flows within a designated Power Platform environment. The objective was to identify flows that were running for an extended period, signifying a potential technical issue.

How the Automated Flow Management Works in Power Automate

The automated flow I created continually monitors all flows in the specified Power Platform environment. When it detects a flow that has been running for an unusually long time, indicating a potential technical glitch, it promptly triggers an email notification to alert the designated personnel.

This notification serves as an immediate alert, prompting the environment administrator to investigate and rectify the technical issue causing the flow to stall. With this automated flow management process in place, timely interventions ensure that business transactions are not unduly delayed, and resources are optimized for efficient system performance.

Advantages of Automated Flow Management

The benefits of automating flow management within the Power Platform environment are profound. This approach significantly reduces the time and effort spent on manual monitoring. Instead of sifting through numerous flows manually, the automated system efficiently pinpoints flows that require attention, allowing administrators to prioritize troubleshooting and resolution.

Key Advantages at a Glance:

  • Time Efficiency: Automated monitoring ensures swift identification of flow issues, saving crucial time for administrators.
  • Resource Optimization: Proactive identification and resolution of stalled flows optimize resource utilization within the Microsoft 365 ecosystem.
  • Enhanced Productivity: Reduced manual efforts mean administrators can focus on critical tasks, boosting overall productivity.

Embrace Automation for an Efficient Power Platform

In today’s fast-paced digital landscape, automation is a game-changer. Utilizing Power Automate to automate flow management in the Power Platform environment not only resolves technical glitches promptly but also enhances the overall efficiency of business processes.

By implementing automated flow monitoring, you unlock the true potential of the Power Platform, ensuring optimal performance and seamless business operations. Embrace automation and elevate your Power Platform experience to new heights, driving productivity and success for your organization.

Before we get into this flow demo, let us understand the challenges businesses face if we don’t automate the flow management process.

Realtime Use Cases: The Challenge of Managing Power Platform Environments without Automation

The following are the challenges businesses face if we don’t automate the flow management process:

Time Limitations and Process Bottlenecks

Without the capability of automation of flow management in Power Automate, managing complex and lengthy processes becomes a significant challenge. Consider scenarios where critical business processes involve tasks that span extended periods. For instance, managing large-scale data migrations, complex calculations, or intricate approval processes can often take a considerable amount of time. In a conventional workflow or flow, managing these processes becomes cumbersome due to the limitations of actions due to time constraints.

In such situations, businesses may face bottlenecks, delays, and even potential errors due to interruptions in the workflow or flow. The inability to handle long-running flows can impede the smooth operation of business processes, leading to frustration among employees and a potential loss of efficiency.

The Business Problem: Delays and Inefficiencies

Imagine a scenario in a retail organization where new product inventory needs to be updated in the system. This process involves data collection, validation, approval, and finally updating the database. Without the automation of flow management in Power Automate, this process could potentially be split into multiple smaller flows, causing delays and inconsistencies in updating the inventory.

Additionally, in scenarios like customer onboarding, where various steps require sequential completion, if the automation is constrained by time limitations, it can result in incomplete or erroneous onboarding processes, causing customer dissatisfaction and a negative impact on the organization’s reputation.

Solving the Business Problem: Leveraging Long Running Flows in Power Automate

Implementing automation for long-running flows in Power Automate provides a solution to these challenges. This automated, long-running flow allows for the uninterrupted execution of processes, irrespective of their duration, ensuring smooth and efficient handling of complex tasks. And send the flow execution status to the Power Platform Environment administrator or the person who owns this flow or environment. Then the flow owner or administrator can take appropriate action if any flows are stuck in execution. Let’s take the example of the retail and customer onboarding scenarios.

In the retail scenario, utilizing the automated status of long-running flows would enable a seamless inventory update process. The automation can run without interruptions, consolidating the steps and enhancing the accuracy and timeliness of product inventory updates.

For customer onboarding, automated long-running flows ensure that each step is completed accurately and in a timely manner, resulting in a streamlined onboarding process, improved customer satisfaction, and a positive impact on the organization’s reputation.

Demo: Get Long Running Flows in Power Automate Environment Step by Step

For this demo, we should have the following prerequisites:

  • A Power Platform Administrator or Environment Administrator account
  • Premium license for “HTTP with Azure AD” or you subscribe for the 90-day free trial. Over the course of the flow demonstration, you will learn how to subscribe to the 90-day free trial of the premium connection.
  • At least you should have a flow scenario that runs for at least more than 30 minutes; if you don’t have one, don’t worry; we will show you how to make an existing test flow long-running—any duration as per our configuration, it could be any minutes or hours.

Step 1: Create a Scheduler Type Flow

Create a test scheduler-type flow in your Power Platform environment.

Scheduler flow in Power Automate
Scheduler flow in Power Automate

Here, configure the interval with any numbers and select the frequency of execution. In the above recurrence, we have configured that this flow should run every 3 hours automatically.

 

If you want to copy and paste this demo, follow each configuration; you must name your actions exactly the same way we have named them.

 

Step 2: Add List Flows as Admin (V2) action to get all flows from a Power Platform Environment

Add a “List Flows as Admin (V2)” action and pass your Power Platform environment. Learn how to work with List Flows as Admin (V2).

List flows as admin (V2) - get flows from an environment
List flows as admin (V2) – get flows from an environment

To know more about “List Flows as Admin (V2)” and how it works, please read this article: Power Automate: Get All Flows in Environment – List of All Flows In The Environment

Step 3: Compose action to find the length of the List Flows as Admin (v2) result

Add a compose action to find the length of the List Flows as Admin (v2) result where pass the below input:

length(outputs('List_Flows_as_Admin_(V2)_|_GetAllFlowsFromEnvironment')?['body/value'])

Compose action to find the length of the List Flows as Admin (v2) result

Compose action to find the length of the List Flows as Admin (v2) resultNote:

  • This compose step is an optional, but good to have to see the result total count.

Step 4: Loop through All the flows

Add an “Apply to each” control.

Apply to each control to loop through each flows from the environment
Apply to each control to loop through each flows from the environment

For the “Select an output from previous steps” box, pass the “value” from the “Dynamic contentList Flows as Admin (V2) | GetAllFlowsFromEnvironment“.

You can directly copy paste the below text value as well:

@{outputs('List_Flows_as_Admin_(V2)_|_GetAllFlowsFromEnvironment')?['body/value']}

 

Step 5: Get all the Running instances of flows

With in the Loop add an “HTTP with Azure AD” premium connector and select an “Invoke HTTP request” action.

HTTP with Azure AD - Invoke an HTTP Request
HTTP with Azure AD – Invoke an HTTP Request
HTTP with Azure AD - Invoke an HTTP Request Configuration
HTTP with Azure AD – Invoke an HTTP Request Configuration

Pass the following connection details as mentioned below:

Note:

  • The above two URLs should be exactly the same as shown above, including the end slash. You just need to copy and paste them.
  • Then, you need to sign in using your Microsoft account.
Invoke an HTTP Request REST API Configuration
Invoke an HTTP Request REST API Configuration

The following is the configuration of the “Invoke an HTTP request” action:

  • Method: Get
  • Url of the request: Please see below:
https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/@{items('Apply_to_each_|_Loop_through_all_the_flows')?['properties/environment/name']}/flows/@{items('Apply_to_each_|_Loop_through_all_the_flows')?['name']}/runs?api-version=2016-11-01&$filter=Status%20eq%20%27running%27

Note:

  • The above query is fetching only the running status flows.

Now, save the flow.

Once we try to save this flow, we will get the below error – as we are using the premium connector:

This flow’s owner needs a premium license: How to fix it?

This flow includes premium capabilities that require a premium license. Please do one of the following:

  • Sign up for a free 90-day trial
  • Send a license request to your admin
  • Buy your own license

It can take up to 7 days for the system to update your license. To use your flow right away, edit and resave it after enabling your new license or trial.

Your flow is saved but can't be used. Select flow checker to troubleshoot.

Your flow is saved but can’t be used. Select flow checker to troubleshoot.

Let’s go with the “Sign up for a free 90-day trial” approach.

Click on the “Sign up for a free 90-day trial” link.

Start your free 90-day trial premium license
Start your free 90-day trial premium license

Click on the “Start trial” button.

After sometimes, your trial will be activated. That’s it. Now, let’s continue with flow demo.

Below are the configurations for the “Invoke an HTTP request” actions:

Invoke an HTTP Request REST API Configuration - Get all running flows
Invoke an HTTP Request REST API Configuration – Get all running flows

Now, let’s perform a test run for this flow.

Invoke an HTTP request to Get all running flows in Power Automate
Invoke an HTTP request to Get all running flows in Power Automate

Copy the entire “Body” text into a notepad, like below:

{
"value": [
{
"name": "08585049458897105041889810209CU50",
"id": "/providers/Microsoft.ProcessSimple/environments/Default-f10e1e03-fffa-47d0-86f4-d0e3c317c65d/flows/63351b1a-b72c-4abe-b0b8-023f60ad9e2b/runs/08585049458897105041889810209CU50",
"type": "Microsoft.ProcessSimple/environments/flows/runs",
"properties": {
"startTime": "2023-10-07T06:43:15.7725914Z",
"status": "Running",
"correlation": {
"clientTrackingId": "08585050023933356130358578702CU82",
"clientKeywords": [
"resubmitFlow"
]
},
"trigger": {
"name": "When_an_item_is_created_or_modified",
"inputsLink": {
"uri": "https://prod-16.westus.logic.azure.com:443/workflows/46df992d7f1e4dd8940d639a5f886ae3/runs/08585049458897105041889810209CU50/contents/TriggerInputs?api-version=2016-06-01&se=2023-10-07T10%3A00%3A00.0000000Z&sp=%2Fruns%2F08585049458897105041889810209CU50%2Fcontents%2FTriggerInputs%2Fread&sv=1.0&sig=xpyergaS588qWcZPmppuU2WNtIH92yETYi3IHvoCdpc",
"contentVersion": "C9ambHQhhZ0aXilLeat4XQ==",
"contentSize": 349,
"contentHash": {
"algorithm": "md5",
"value": "C9ambHQhhZ0aXilLeat4XQ=="
}
},
"outputsLink": {
"uri": "https://prod-16.westus.logic.azure.com:443/workflows/46df992d7f1e4dd8940d639a5f886ae3/runs/08585049458897105041889810209CU50/contents/TriggerOutputs?api-version=2016-06-01&se=2023-10-07T10%3A00%3A00.0000000Z&sp=%2Fruns%2F08585049458897105041889810209CU50%2Fcontents%2FTriggerOutputs%2Fread&sv=1.0&sig=LJ2FAgCiAhD1LUm5KeOpXY5JtEI2RybMiZuHCtOa7yQ",
"contentVersion": "qXYgpp7IgTQVhvdtkYx5ZA==",
"contentSize": 3889,
"contentHash": {
"algorithm": "md5",
"value": "qXYgpp7IgTQVhvdtkYx5ZA=="
}
},
"startTime": "2023-10-07T06:43:15.7660171Z",
"endTime": "2023-10-07T06:43:15.7660171Z",
"originHistoryName": "08585050023933356130358578702CU82",
"sourceHistoryName": "08585050023933356129358578702CU136",
"correlation": {
"clientTrackingId": "08585050023933356130358578702CU82",
"clientKeywords": [
"resubmitFlow"
]
},
"status": "Succeeded"
}
}
}
]
}

 

Step 6: Parse JSON for the Get all running flows

Add a “Parse JSON” data operation action.

In the content box, pass the “body” from the “Invoke an HTTP request | Get all running flows” action, from which you can select the Dynamic Content tab.

You can even copy paste the below body text for this configuration:

@{body('Invoke_an_HTTP_request_|_Get_all_running_flows')}
Get all running flows in Power Automate JSON
Get all running flows in Power Automate JSON

For the schema configuration, click on the “Generate from sample” link, then copy and paste the big body text you have copied in the notepad (“Invoke an HTTP request | Get all running flows” output).

For more details about the Parse JSON in Power Automate and how it works – please refer to this article: Master in How To Parse JSON in Power Automate Step by Step Guide

Step 7: Add Condition Control to Verify the Total Result Count

Add a condition control to verify the total result count. Copy and paste the below text:

length(body('Parse_JSON_|_Get_all_running_flows')?['value'])
Add condition control to verify the total result count
Add condition control to verify the total result count

If the result is greater than 0, perform the below steps in the “Yes” branch.

Step 8: Add Filter Array Action to Verify whether we have a long running flow

Add a filter array data operation action to verify whether we have a long-running flow.

Select the “value” from the “Parse JSON | Get all running flows” under the dynamic content tab and place it into the “From” box.

You can even copy paste the below text:

@body('Parse_JSON_|_Get_all_running_flows')?['value']

Then, add the below filter criteria:

@less(addMinutes(item()?['properties']?['startTime'], variables('varIntFlowIsRunningHowManyMinutes')), utcNow())

Click on the “Edit in advanced mode” link and you need to copy paste above text.

Note:

  • In this filter criteria, we have passed the dynamic variable value (varIntFlowIsRunningHowManyMinutes) for the flow that is running for how many minutes; here we can pass the static integer value.
  • Basically, it is filtering the flows from the running instances that are running for the last ‘N‘ minutes, where ‘N‘ is a configurable variable.

 

Filter Array Action in Power Automate to get long running flows
Filter Array Action in Power Automate to get long running flows

Add one more “Condition” control to verify whether the above filter array returns more 0 flows; if yes, send an email to the flow owner or administrator. To check this, add the below text in the condition:

length(body('Filter_array_|_Long_Running_Flows'))

If this condition returns a value greater than 0, add an “Send an email (v2)” action.

Send Long Running Flow Details Administrator in Power Automate
Send Long Running Flow Details Administrator in Power Automate

In the above, email configuration is very simple, where we have a static text along with some dynamic value.

The dynamic values are below:

  • Flow Display Name: Select from the dynamic content List flows as Admin (V2)
  • Total Running Flow Length: See the value below:
    length(body('Parse_JSON_|_Get_all_running_flows')?['value'])
  • Total Long Running Flow Length: See the value below:
length(body('Filter_array_|_Long_Running_Flows'))
  • Flow Is Running For How Many Minutes?: This is integer type variable, you can select it from the dynamic content.
Initialize integer type variable in Power Automate
Initialize integer type variable in Power Automate

By now, we have completed the setup for the long-running flow report. Now we need to run the flow to test the functionality.

As we said at the beginning, we should have at least a long running flow—at least running for more than 30 minutes. How do we get this flow for this test? It is very simple. Create an automated cloud flow with a trigger when an item is created or modified and attach it to the SharePoint Online List or Document Library. After that, add a “Delay” action where you configure the count as 40 or something more than 30 and the unit as a minute. This means this flow will be running with a ‘N‘ (any number) minute delay. Finally,  you can add the send an email (V2) action.

 

Power Automate Flow Delay Action Configuration
Power Automate Flow Delay Action Configuration

Trigger this flow and have a tea or coffee break, and after 30 minutes, run your long-running flow.

For this demo, let’s run this flow manually; generally, it will be running automatically based on the scheduled configuration.

Let’s wait to complete this flow successfully.

Your flow ran successfully - Long Running Flow Status in Power Automate
Your flow ran successfully – Long Running Flow Status in Power Automate

Once this flow runs successfully, we can see the below email:

Power Automate Long Running Flow Report Email Demo
Power Automate Long Running Flow Report Email Demo

Here is the complete flow screenshot:

Monitor Long Running Power Automate Flows - Part 1

Monitor Long Running Power Automate Flows - Part 2

Get Long Running Power Automate Flows
Get Long Running Power Automate Flows

Summary: Monitor Long Running Power Automate Flows (Long Running Flows)

Thus, in this article, we have learned about how to get the long-running flow details and how to monitor these long-running flows automatically with the help of Power Automate Flow.

In the world of Power Platform, handling many flows can be hard, especially when some get stuck and take a long time to finish. To tackle this, I created a smart solution using Power Automate. This special automated system constantly checks all the flows, looking for ones that are taking too long. When it finds one, it sends a quick email to the admins so they can fix the problem fast. This clever way of managing flows saves time and helps everyone work better by using computer power wisely. It’s like having a helpful assistant in the Power Platform toolbox!

See Also: Other Power Platform Articles

You may also like the following Power Platform Articles:

If you find this article helpful and informative, we’d greatly appreciate your support by liking and sharing it within your network of friends and colleagues. Thank you for being a part of our learning journey in Power Automating!

 

About Post Author

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