Cancel Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
I'm trying to cancel a workflow associated with a story. I'm following this community post which has a correct answer.
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader