How do you cancel workflow and restart a new version on a request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2017 01:19 PM
I need to write a fix script or a simple ui action that will cancel the current workflow on an RITM record and start a new version of the same workflow.
In short, we made changes to fix the workflow for a catalog item. Now that we have moved it to prod, we need to reset all the RITM records using the old context of the workflow so that it uses the new version of the workflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2021 09:28 AM
This script only worked for one record at a time, it did not work for me if i tried to use for 3 records using the "addEncodedQuery" method.
var query1='cat_item=b970c90ed9dff00ba961955^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()';
var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery('query1');
gr.query();
while(gr.next()) {
new WorkflowApprovalUtils().cancel(gr);
new Workflow().startFlow(new Workflow().getWorkflowFromName('Access Workflow'), gr, '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 05:51 AM
How can cancel and restart workflow of multiple records at a time using background script? Below script is not working but only single record get updated:
var oldWorkflow = new global.Workflow();
var gr = new GlideRecord("table_name");
gr.addQuery('state',1);
gr.query();
while (gr.next()) {
oldWorkflow.cancel(gr);
new Workflow().startFlow(new Workflow().getWorkflowFromName('Workflow name'), gr, '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 08:37 PM
Hello Swagatam,
You can run the glide query inside a for loop. Please see the example below:
var sysIDs = "sys_id_0,sys_id_1,sys_id_2";
// Convert the above string into an array
var arr = sysIDs.split(',');
for (var i = 0; i < arr.length; i++) {
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", arr[i].toString());
gr.query();
if (gr.next()) {
new WorkflowApprovalUtils().cancel(gr);
new Workflow().startFlow(new Workflow().getWorkflowFromName("<Name of the Workflow>"), gr, '');
}
}
Thanks