- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 07:17 AM
Hi all,
We have an updated workflow for the RITM and would like to attach the latest workflow to existing RITM records (roughly 20 of them).
Can anyone share me the script to do so? I found only restartWorkflow which restarted the existing workflow instead of attaching new workflow to existing records.
Thank you
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 09:00 AM
You can do it, but I'd typically agree with David that just letting the existing ones run their course is the best option. To do it "right" you would need to cancel the existing workflow, and then attach the new workflow.
I also strongly suggest you test out anything carefully on a DEV instance before you try this in PROD, and when you do go to PROD, just start with one record and validate.
That being said, you can do what you are looking to do from a background script with something like the following:
var current = GlideRecord('sc_req_item');
//Get the record you want as a GlideRecord object.
current.get('<ritm-sys_id>') //replace this with a sys_id of one of the RITMS you want to use.
//First, we cancel any running workflows.
var workflow = new Workflow();
workflow.cancel(current);
var flowID = '592e5b661bd20010917ca9b4bd4bcb86' //This is the sys_id of the workflow you want to attach from the wf_workflow table
//Now we attach the new workflow
startWorkflow(flowID, current);
//Helper functions
function startWorkflow(id, current) {
var w = new Workflow();
var context = w.startFlow(id, current, current.operation(), getVars(current));
if (context != null)
current.context = context.sys_id;
}
//Get the variables to pass to the workflow
function getVars(current) {
var vars = {};
for (var n in current.variables)
vars[n] = current.variables[n];
return vars;
}
In the RITM you will see any existing, open tasks set to closed incomplete, with all new tasks being added. Does make for a bit of a messy read in the task list.
If this was helpful, or correct, please be kind and remember to click appropriately!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 02:08 AM
Totally worked for my case👍 Thank you for sharing!