How to restart workflow for a requested item (RITM) using a background script?

ashwanikumar
Tera Expert

Hi All,

 

I need to cancel current workflow and start a new workflow as current workflows have stucked in a wrong script activity in requested items (RITMs). How can i achieve it?

 

Thanks,

Kumar

4 REPLIES 4

Dante Ditan
Kilo Sage

Hi,

 

var gr = new GlideRecord("sc_req_item");

if(gr.get('sys_id')){


new Workflow().restartWorkflow(gr);

}

Thank you

Dante

Hi @Dante,

 

Thanks for the quick reply 🙂 Will it also cancel existing workflows attached to a RITM??

 

Thanks,

KUMAR

 

 

For cancelling you should add this also:

 

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

Tim Deniston
Mega Sage
Mega Sage

See this thread with Chuck Tomasi's correct answer: https://community.servicenow.com/community?id=community_question&sys_id=3e998ba5db5cdbc01dcaf3231f9619ad

 

"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."