- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 08:15 PM
we have a table in custom application scope , that has workflows tied to it. When the review goes into Cancelled , the workflow needs to go be cancelled.
Tried the below script , but the workflow isn't getting cancelled.
Log--C is printed once, but the workflow isn't cancelled. There are 2 workflow contexts for the record, where one is finished , the other one is in progress.
var grContext = new GlideRecord("wf_context");
grContext.addQuery('id', current.sys_id);
grContext.query();
while (grContext.next()) {
gs.info('Log--C');
new global.Workflow.cancelContext(grContext.sys_id);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 09:59 PM
Hi @Kumar38
You can use below code to cancel all running workflows for a given record
var workflow = new global.Workflow();
workflow.cancel(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 09:59 PM
Hi @Kumar38
You can use below code to cancel all running workflows for a given record
var workflow = new global.Workflow();
workflow.cancel(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 10:02 PM
If you want to only cancel a particular workflow associated with the ‘current’ record, then use below code
//Query for all executing workflow contexts
var flows = new Workflow().getRunningFlows(current);
while(flows.next()){
//Check for associated workflows by name - Example Routine Change is being cancelled
if(flows.workflow_version.getDisplayValue() == 'Routine Change'){
//Cancel the workflow context
new Workflow().cancelContext(flows);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 11:37 AM
Above recommendations no longer work because ServiceNow added a new BR to prevent the change. So to accomplish the change run the following script: