how to start or restart a workflow context without passing stages by default in servicenow?

anjalikulkarni
Kilo Contributor

We have a requirement where I want to restart the workflow that is already finished. We have used the script mentioned below   to restart the cancelled workflow but after restarting, the workflow is passing the stages by default.

var wkfw = new Workflow();

//var cancelflow = wkfw.getWorkflowVersionFromName('Workflow name');

var wfgr = new GlideRecord("wf_workflow");

wfgr.addQuery("name","'Workflow name");

wfgr.query();

if(wfgr.next()){

var wfid = wfgr.sys_id;

var x = new WorkflowApprovalUtils().reset(current, "res");

var context = new Workflow().startFlow(wfid, current, current.operation());

}

To restart the workflow, we have referred to the link below Restart a workflow context without affecting other workflows running on the record

Can anyone please guide on the same?

9 REPLIES 9

Chuck Tomasi
Tera Patron

Two things:


  • Is the workflow looking for conditions (e.g. populated fields, fields with certain settings, etc) that may also need to be reset (e.g. change current.state back to 1, for example)?
  • Have you tried restartWorkflow() instead of startFlow()? startFlow() starts a specific flow (instantiating another context on the current record). restartWorkflow() resets the one that's already there.

Your solution may actually be a combination of these two.



Reference: Workflow Script - ServiceNow Wiki


Hello Chuck,



Thanks for reply!



we have initially tried restartWorkflow() but this method restarting all workflows associated (currently we have two workflows on same) since the argument need to be passed to this restartWorkflow() is current.



In our case, we should restart only one workflow (one context) instead of all.



Can you please guide us if we have any way to restart specific workflow context (instead of all)? we tried solution given from the link Restart a workflow context without affecting other workflows running on the record


but its not helpful.



Any help would be much appreciated!



Thanks,


Pavan.


Unfortunately I don't see a way to selectively start one workflow when multiples are attached to a given record. Sorry.


Hello Chuck,



Below is the way to restart a specific workflow :



new Workflow().startFlow(wflw.getWorkflowFromName('name of the workflow'), current, 'update');



Hope it helps.



Regards,


Khushboo