Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Jacqui
ServiceNow Employee
ServiceNow Employee

This example doesn't show the maintainStateFlag in the restartWorkflow function. It looks like it defaults to true but the user might want a false to reset all of the values.

akashsrm100
Kilo Guru

Hi Midhun to restart workflow i created a bussinees rule on update.


That may help you


function onAfter(current, previous) {


    //This function will be automatically called when this rule is processed.


}


forceReqItemUpdate();


function forceReqItemUpdate() {


    var wf = new Workflow();


  var ri = new GlideRecord('u_trips');


    ri.addQuery('sys_id', current.sys_id);


  ri.query();


  if (ri.next()) {


          wf.restartWorkflow(current);


    }


}



Thanks


Akash Sharma


PS hit Like Correct if helps


Midhun1
Giga Guru

Hi All,



Am testing in background script:


Am using


new WorkflowApprovalUtils().cancelAll(current, comment);


new Workflow().restartWorkflow(current);



Still workflow is in same stage.


Did you make a record called "current"?



This video shows how you can be very effective using scripts background.



Faster Server Side Script Development and Test