Cancelling all running flows in Power Automate

Finding out that you have a scheduled flow in Power automate or Microsoft Flow (What ever name it has this week), that just continue to run and then the next flow dows the same and all of a sudden, you have a gazillion flows running and never stopping. Well according to the Power automate limits, they will be cancelled after 30 days.

But you don’t have the option to turn the flow off and the wait 30-days until you can turn it back on again – I assume. And you have a list that look like this:

The behavior mostly happens, when a workflow starts, before the previous has finished. You can take a look at this article by Pieter Veenstra on how to troubbleshoot the flow to dig deeper into the how and the why. Here is a few ways to prevent it and to deal with it.

  1. Set the degree of parallelism to 1, then you will only have one flow running. Then you will discover immediately if it hangs.
  2. Cancel all the running flows
  3. Make a copy of your flow, export it, then import it and delete your old flow (not a fan of this option but it will work)
  4. Check if lists or items or sites etc. Exists before you try to create them. If you need to check for new items in a list and run stuff for each item, then make a condition to only run, if there is any items.
  5. Make a list, with a single item that reads “locked” or “Unlocked”, then at step 1, check if item is unlocked, if not, terminate the flow. If “unlocked = true, then set it to locked, and then run flow. As a final step, set the item back to “unlocked”.

Set the degree of parallelism to 1

  1. If you have a recurring flow, click on the steps menu “…” and the “Settings”.

2. Activate “Concurrency Control” and then set the “Degree of Parallelism” to 1

Cancel all the running flows

Thank you to the ever brilliant users in the “Microsoft Power Automate Community” for delivering this solution. This is just brilliant.

  1. Navigate to the flow in question
  2. Click on “All runs”

3. Filter the view to only show the running flows

4. Open the console in the browser (hit F12 and the select console)
5. Paste in the code below. For some reason I need to paste the jquery part twice before the actual action code, but it works like a charm. Depending on the number of flows you have running, this can take quite a while.

//Include jquery (you may need to paste this following twice)
var jq = document.createElement('script');
jq.src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict()
// Cancel all running flows ( This part you only paste once)
confirm = function () {return true;};
setInterval(function () {
$(".fl-StatusInCell:contains('Running')").parent().parent().find('.ms-DetailsRow-cell').first().click();
$(".fl-StatusInCell:contains('Running')").parent().parent().find('.ms-DetailsRow-cell').last().click();
$(".fl-StatusInCell:contains('Running')").parent().parent().find('.ms-DetailsRow-cell').first().click();
$('button[name="Cancel"]').click();
},3000);

6 thoughts on “Cancelling all running flows in Power Automate”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.