Need Script to Stop/Interupt Workflow from Creating Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 01:02 PM
Anyone able to help with how to stop active flows from running and creating tasks?
I need to close out a large group of SC_tasks that had not been getting assigned to an assignment group. However the service catalog item has a workflow that creates a task after the ones I want to close is completed.
How can I close out the tasks I want but stop the workflow from running and creating the next task in the flow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 01:53 PM
Hi, you can run a script to update\close your tasks and in it set both a state value and active = false,
also calling method setWorkflow(false);
GlideRecord | ServiceNow Developers
and this should prevent your workflow (and any other BR's) from running against the task you are updating.
But, the workflows for these tasks will also need to be cancelled.
Workflow | ServiceNow Developers
Untested and based on the documentation linked, not personal experience, but I would think something like this.
var gr = new GlideRecord('yourTaskTable');
gr.addEncodedQuery('filterForYourTaskList');
gr.query();
while gr.next()) {
//update your task
gr.setWorkflow(false);
gr.active = false;
gr.state = yourClosedStateValue;
gr.work_notes = 'Cancelled by Blabalbal';
//update any other fields
gr.update();
//update workflow, if one is running on your task.
if(gr.context) {
var w = new Workflow();
var now_GR = new GlideRecord('wf_context');
if (now_GR.get(gr.context)) {
w.cancelContext(now_GR);
}
}
}