Restart new Version of workflow on Active Records that are still in initial state

vhari2
Tera Expert

Hi . I have updated my workflow and want to move to Prod . I did some research and found that the active records will still be using the old context as the workflow already started for them and they are in the middle . But there are records that were created but are still in the first step of the workflow. I would like to update these records with the new context of workflow. Can anyone please help me with the code on how to achieve this .

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

While I don't have time to write entire script, it's going to a pretty standard GlideRecord lookup for the records you want to restart. The key is going to be the Workflow() class. Use the cancel() method to kill the workflows on the records and then right after that, use startFlow() method to start a specific flow.

Developer: startFlow

View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

While I don't have time to write entire script, it's going to a pretty standard GlideRecord lookup for the records you want to restart. The key is going to be the Workflow() class. Use the cancel() method to kill the workflows on the records and then right after that, use startFlow() method to start a specific flow.

Developer: startFlow

Thanks Chuck

 

I have wrote the following to resolve my issue 

 

var gr = new GlideRecord ('table name');
gr.addEncodedQuery('active=true^state=41');
gr.query();
while (gr.next()) {
var oldWorkflow = new Workflow();
oldWorkflow.cancel(gr);

var w = new Workflow();
var context = w.startFlow('fe694ca94ffb4600e9153d728110c79c', gr, gr.update());
}

lcbell
Tera Expert

I think this will do it using the appropriate gr for the task
new Workflow().restartWorkflow(gr, false);//restartWorkflow related workflows

According to how I read it, restartWorkflow() simply triggers the same workflow (restarting the context) and allowing you to reset tasks/approvals on that same flow. That's different than canceling the existing flow and starting a new specific one.