Finding out that you have a scheduled flow in Power Automate, that just continue to run and then the next flow does 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”.
Set the degree of parallelism to 1 in Power Automate so the flow cannot run in parallel and thus create havoc on your tenant.

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

Setting the concurrence Control in a Power Automate flow

Cancel all the running flows in Power Automate

When you open the console in edge you will have the option to input some scripts to handle the output on the screen. Getting some help in the comments, the fastest way to achieve this is to follow the instructions below:

  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.
Selecting all running flows in Power Automate overview.
//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);

11 responses to “Cancel or stop all running flows in Power Automate”

  1. Rajesh Avatar
    Rajesh

    A true Automation. Thanks a ton!

  2. Frank Avatar
    Frank

    TIGHT! Thanks for all of this! Saved my bacon!

  3. johannesin8 Avatar
    johannesin8

    Thanks for this! brilliant tip!

  4. falumi Avatar

    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

  5. seanhod Avatar
    seanhod

    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

    1. Ulrich Gerting Bojko Avatar

      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.

  6. Mike Avatar

    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.

  7. Matt M. Avatar
    Matt M.

    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);

    1. Ulrich Gerting Bojko Avatar

      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 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

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