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.
- Set the degree of parallelism to 1, then you will only have one flow running. Then you will discover immediately if it hangs.
- Cancel all the running flows
- 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)
- 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.
- 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
- 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.
- Navigate to the flow in question
- Click on “All runs”
- Filter the view to only show the running flows
- Open the console in the browser (hit F12 and the select console)
- 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);
// Cancel all running flows ( This part you only paste once)
confirm = function () {return true;};
setInterval(function () {
$(“.fl-StatusInCell:contains(‘Running’)”).parent().parent().parent().find(‘.ms-DetailsRow-cell’).first().click();
$(“.fl-StatusInCell:contains(‘Running’)”).parent().parent().parent().find(‘.ms-DetailsRow-cell’).last().click();
$(“.fl-StatusInCell:contains(‘Running’)”).parent().parent().parent().find(‘.ms-DetailsRow-cell’).first().click();
$(‘button[name=”Cancel flow run(s)”]’).click();
},3000);
Fantastic, this was my life saver
awesome!!! saved me a ton of time. Thank you.
This is awesome mate!.
Life Saver!!!
Thanks man !!
A true Automation. Thanks a ton!
Awesome Man!!
We need to know who the active site owners are of more than 4000 sites. I had a flow that sent an approval to all site owners of sites (we ran 100 at a time) and some sites have multiple owners so it looped through. After 3 days of no response it escalated to the owners manager with another approval. The approval was Yes, I own the site or No, I don’t own this site. A lot of people didn’t reply so may escalated to managers. I have some managers who own 100-400 sites so there were getting bombarded with emails. (I am going to rewrite the flow!). I ran this code and it stopped more than 700 flows from running and saved me from dealing with irate managers! Thank you!
Hi Bob. I am so glad that this little trick could help you out. Thank you for taking the time to write a comment and letting me know that it made a difference.
Great !! Thanks a lot!!
Another life saved!
Another life saved!! Thank You!!
another life saved here too…Awesome code
TIGHT! Thanks for all of this! Saved my bacon!
Stumbled upon this when trying to cancel A LOT of running flows that was triggered due to a bulk update.
Just some questions; will the canceling of runs be updating “live” or only when it’s completed? Also will it try to cancel the oldest or newest run first?
It should update live. As far as i can remember, it will fix the newest ones first, as they are at the top of the list.
Does this work for you? I get some number after using the second JS but I see no other outcome.
Great !! Thanks a lot. Tip: change the label according to the language (ex: ITA: ‘Running’ –> ‘In esecuzione’, ‘Cancel’ –> ‘Annulla’)
Brilliant tip. Thanks for sharing Andrea. 👍
Thanks for this! brilliant tip!
I’m trying to use this, in Edge. I did have to push in the jquery twice, but after that, when I’m executing the second script, the screen doesn’t show anything. on the console, though, i’m getting errors:
main.279ec6d3.js:2
Uncaught TypeError: Cannot convert undefined or null to object
at Function.getOwnPropertyNames (<anonymous>)
at K (main.279ec6d3.js:2:130985)
at W (main.279ec6d3.js:2:130613)
at i (main.279ec6d3.js:2:173915)
at main.279ec6d3.js:2:174015
does anyone have any insight into this?
tks
I tried running this in Chrome and it seems that there is an alert dialog that gets in the way of this working. Perhaps, this was added after the post was written.
I was curious about why there was a function in the script “named” confirm that just returns true. I’m not clear on the purpose of that part, it doesn’t seem to be used anywhere.
this seems to be where I am stuck – were you ever able to resolve this?
Normally when you click Cancel flows, a modal dialogue comes up asking you to confirm. I believe this code automatically clicks the OK on that pop up.
Hi, thanks for this.
I have 120000 flows to cancel. This code is running ok but it is not deleting any of the running runs unless I keep manually changing selections. Am I missing something?
thanks,
Sean
You should be able to go into “All runs – Running” and then only get the running flows. From there you can run the code, but I don’t know how many it will process before the list is empty and you need to repeat the action. 120000 flows is going to take some time cleaning up though.
Alternatively you could try this:
1. export the flow
2. import the flow and then set it up again
3. delete the original flow. That “should” delete all the running instances.
Disclaimer: I haven’t tried this myself so results may vary.
I needed to select the first item to make the Cancel button show, and from then on it worked.
mine just flashes – appears to be working but isn’t actually cancelling anything. The confirmation box never appears.
After I select the first item – it appears to be working (screen flashing)…but it’s not actually deleting any? Did something change? I never see the confirmation box like when I do them manually.
The button named changed so be sure to updated the code so that it looks for the new name “$(‘button[name=”Cancel flow run(s)”]’).click();”. Also I removed the “jQuery.noConflict()” part since that was causing issues. After that, click the first item in the list so that the Cancel button shows up and then it should start working.
Hey everyone, looks like the html has changed on the page, which breaks the targeting that the jquery does. Basically the name of the cancel button changed, and the amount of nesting for each row changed. Here’s the updated code that worked for me:
//step 1. only need to past this once in chrome
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);
//step 2.
confirm = function () {return true;};
setInterval(function () {
$(“.fl-StatusInCell:contains(‘Running’)”).parent().parent().parent().find(‘.ms-DetailsRow-cell’).first().click();
$(“.fl-StatusInCell:contains(‘Running’)”).parent().parent().parent().find(‘.ms-DetailsRow-cell’).last().click();
$(“.fl-StatusInCell:contains(‘Running’)”).parent().parent().parent().find(‘.ms-DetailsRow-cell’).first().click();
$(‘button[name=”Cancel flow run(s)”]’).click();
},3000);
Hi Matt
Thank you for the edit. I’ve updated the code in the post. I’ve deleted the other comments you made so it doesn’t post twice 🙂