How to Restart any workflow?

Midhun1
Giga Guru

I have an Requirement to restart an existing 'Workflow'.A task already   got triggered in the existing one, i want to restart it from the beginning.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Midhun,



Take a look at the Workflow script include. There is a method called restartWorkflow(). It takes two arguments, the gliderecord object related to the workflow you want to restart, and a boolean to indicate whether to keep approvals in their current state or reset those as well.



Reference:


Workflow Script - ServiceNow Wiki


View solution in original post

8 REPLIES 8

Chuck Tomasi
Tera Patron

Hi Midhun,



Take a look at the Workflow script include. There is a method called restartWorkflow(). It takes two arguments, the gliderecord object related to the workflow you want to restart, and a boolean to indicate whether to keep approvals in their current state or reset those as well.



Reference:


Workflow Script - ServiceNow Wiki


Hello Chuck,

 

I tried your suggestion. However, in my workflow, there are two approval activities and when the first one is approved and the second one is rejected I want a workflow to restart from the beginning. And when I use restartWorkflow(), workflow starts from the beginning however if first approval activity was approved previously then it let the first activity pass on as it is. And it goes on the second approval activity where approval was rejected. And approval is requested again for second approval activity but not to the first approval activity. And first approval activity is set to not yet requested. For reference, I am attaching a screenshot. Could you guide please how to start the approval activities from the beginning again?

Gurpreet07
Mega Sage

Hi Midhun,



Refer Below Thread


How to Create a BR to Restart the Workflow


marcguy
ServiceNow Employee
ServiceNow Employee

This wiki page should help you, Workflow Script - ServiceNow Wiki



3.18.3 Example


//mark all existing approvals for the change as 'cancelled' and restart the workflow to create new approvals 
//where current is a task record with a workflow context
new WorkflowApprovalUtils().cancelAll(current, comment);
new Workflow().restartWorkflow(current);