How can I cancel a running workflow on a single RITM?

carlav
Kilo Guru

I have a Workflow set to run on RITM that has a timer activity - this appears to be 'broke' on some, not all, of the specific Catalog Item type. Is it possible to cancel the running workflow on single RITM records instead of a whole set or type?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@carlav 

to cancel the workflow you can use this script and specify the RITM sysId

you can run this in background script

var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", "RITM001");
gr.query();
if (gr.next()) {
	// cancel old running workflow
	var flows = new Workflow().getRunningFlows(gr);
	while(flows.next()) {
		new Workflow().cancelContext(flows);
	}  
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Sebastian L
Mega Sage

Hi Carlav,

Check out the documentaiton here

It can be done either by script, or by navigating to "Workflow > Active Contexts". 


Best regards,
Sebastian Laursen

I didn't know about the Active Contexts, that is helpful but somehow the specific RITM I was looking for didn't show up there. I used a script from another answer and was able to cancel. Thanks!

Sagar Pagar
Tera Patron

Hi,

You can cancelled the workflow from workflow context.

1) Navigate to Workflows ---> Active Contexts.

2) On the List View, select the Workflow you want to Cancel.

3) Open that record and Click the UI Action Cancel.

 

OR you can try this script in background scripts.

var cancelWorkflow = new GlideRecord("sc_req_item");
cancelWorkflow.addQuery("sys_id", "RITM_sys_id");
cancelWorkflow.query();
if (cancelWorkflow.next()) {

    new WorkflowApprovalUtils().cancel(cancelWorkflow);  // cancel workflow
}

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Ankur Bawiskar
Tera Patron
Tera Patron

@carlav 

to cancel the workflow you can use this script and specify the RITM sysId

you can run this in background script

var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", "RITM001");
gr.query();
if (gr.next()) {
	// cancel old running workflow
	var flows = new Workflow().getRunningFlows(gr);
	while(flows.next()) {
		new Workflow().cancelContext(flows);
	}  
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader