Ho to restart a change request workflow

VIKAS MISHRA
Tera Contributor

As per the requirement i have created one new UI action button "Refer back" which will be visible in Approval form of the CR along with approve, reject now "refer back" button will also be visible. 

So i added the script in my UI action button that if somebody clicks on this then approval state should moved to "refer back" state (new state i created) and at the same time the workflow should be restarted, which means whatever the tasks was already created and closed before this apporval generation those should be reopened and if we close them again then the approval should also retriggeed ,

 

I tried below mentioned script to restrt the workflow but its not work. i tried this in run script of workflow and in Ui action button also
new global.Workflow().restartWorkflow(current, true);

 

2 REPLIES 2

SumanthDosapati
Mega Sage
Mega Sage

@VIKAS MISHRA 

Try using below sample script as logic 

var gr = new GlideRecord('sc_req_item'); //replace table name
gr.get('sys_id_of_record'); // replace sys_id of record

 var workflow = new Workflow();
      workflow.cancel(gr);

var newWorkflow = new Workflow();
newWorkflow.startFlow(new Workflow().getWorkflowFromName('Pass workflow name here'), gr, '');

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

Mark Manders
Mega Patron

Since you are using the workflow, just add your custom state as output for the approval action and point it back to the start (or add an extra action to reopen the previous tasks and then back to the approval step, instead of creating new tasks).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark