Cancel the running flows with JavaScript code

We will look at how we can use JavaScript to cancel flows that are running without canceling each flow manually. To do this, follow the steps below.

Let’s look at a scenario where we are seeing the flows that are in a running state and are not terminating.

Click on All runs, this navigates you to all flow runs view.

When we are in the All runs view, we need to open the developer console in the browser. The developer console can be opened by clicking F12 (or holding fn and F12) on Windows. Or by right-clicking on the screen and clicking Inspect.

In the developer console, navigate to the Console pane. To clear the console window, click CTRL + L. The console pane is where we will add the JavaScript code that will cancel the running flows. As can be seen in the next step.

// Copy this first and run it in the console
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);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict()

//Paste the same again
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);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict()

// Then copy this in the console to start the cancelation of the flows.
confirm = function () {return true;};
setInterval(function () {
$(".fl-StatusInCell:contains('Running')").parent().parent().find('.ms-DetailsRow-cell').last().click();
$('button[name="Cancel"]').click();
},5000);

Click the running code after the code is implemented in the console, and the output will be seen below

Hope this Helps!


Share Story :

Secured By miniOrange