Restart Workflow for one REQ or RITM

Steven Parker
Giga Sage

Hi Guys,

Is there a simple Business Rule for restarting a workflow on one particular REQ or RITM?

In the event we find an issue, something is incorrect, etc...can you just restart a workflow on one particular Request is what I am looking for.

I've seen this code, but not sure how to use it for one particular item:

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

new Workflow().restartWorkflow(current);

If anyone has a script example that would be great!


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

You can create   UI action 'Restart Workflow' on Request. This button only visible to admins for us and if something goes wrong, we correct few values and restart the workflow.



We have the following code in the UI action.



new WorkflowApprovalUtils().reset(current, "Restarting the workflow");


current.state = "requested";


current.u_last_approved_by = "None";


current.request_state = "requested";


current.update();



Please mark this response as correct or helpful if it assisted you with your question.

So I tried this, but the workflow doesn't seem to restart.   Just hangs at the Begin step:



This was when I first made the request:



find_real_file.png



This is when I clicked "Restart Workflow" button:


find_real_file.png



Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Try below code



//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);



Reference:


http://wiki.servicenow.com/index.php?title=Workflow_Script#restartWorkflow.28current.2C_maintainStat...



Please mark this response as correct or helpful if it assisted you with your question.

I had the same issue (restarted workflow stuck at Begin).   It would seem that "restartWorkflow" is something of a misnomer.   What it actually does is reset the workflow without starting it running.   Once it is reset, you have to "runFlows".   This worked for me:



wkflw = new Workflow();


wkflw.restartWorkflow(current);


wkflw.runFlows(current, 'update');