Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Cancel Workflow

brianlan25
Kilo Patron

I'm trying to cancel a workflow associated with a story. I'm following this community post which has a correct answer.

https://www.servicenow.com/community/itsm-forum/how-can-i-cancel-a-running-workflow-on-a-single-ritm...

However I'm getting an error when using script background and enabling execute in sandbox. The error message is KittyScript validation failed for null.null.script with error: Syntax error: Expected end of expression but found 'gr' at position 4.

Any idea on why this code is not working?

var gr = new GlideRecord("rm_story");
gr.addQuery("number", "STRY517"); //full story number is in the actual code I'm trying to use.
gr.query();
if (gr.next()) {
	// cancel old running workflow
	var flows = new Workflow().getRunningFlows(gr);
	flows.query();
	while(flows.next()) {
		new Workflow().cancelContext(flows);
	}  
}

@Ankur Bawiskar 

1 REPLY 1

Ankur Bawiskar
Tera Patron

@brianlan25 

Did you try unchecking that "Execute in sandbox" checkbox?

also try this updated script

var gr = new GlideRecord("rm_story");
gr.addQuery("number", "STRY517"); //full story number is in the actual code I'm trying to use.
gr.query();
if (gr.next()) {
	// cancel old running workflow
	var flows = new Workflow().getRunningFlows(gr);
	while(flows.next()) {
		new Workflow().cancelContext(flows);
	}  
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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