Attaching new version of workflow to record.

madanm7786
Mega Guru

Hi All,

I created a fix script to cancel executing workflow and to attach a new workflow. It is working fine as expected.

Below is the script.

var gr = new GlideRecord('table_name');

gr.addEncodedQuery('my query');

gr.query();

while(gr.next())

{

var oldwf = new Workflow();

oldwf.cancel(gr);

var newwf = new Workflow();

newwf.startFlow(newwf.getWorkflowFromName('Workflow name', gr, 'insert');

}

 

But i have some records where old workflow is already finished and i need to attach new workflow to these records also. But this is not working. Below is the script.

var gr = new GlideRecord('table_name');

gr.addEncodedQuery('my query');

gr.query();

while(gr.next())

{

var newwf = new Workflow();

newwf.startFlow(newwf.getWorkflowFromName('Workflow name', gr, 'insert');

}

 

Is it not possible to attach new workflow if old workflow is already finished on the record.

Any help here please....

 

Thanks.

 

1 REPLY 1

Brian Lancaster
Tera Sage

Why do you want to attach a new version of a workflow to an already completed one? I think the only way to do that would be to restart the workflow which would cause all task to reopen and all approvals to go back out.

https://www.servicenow.com/community/developer-forum/restart-a-finished-workflow/m-p/1779150