- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 04:24 AM
Need to restart the workflow.
Approval got skipped somehow and workflow is struck. Please let me know how to restart.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 04:52 AM
you can use this script in background for your table record to delete older context and attach new workflow context
(function(){
try{
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('YOUR QUERY HERE'); // PASS your QUERY HERE
gr.query();
while(gr.next()){
// cancel old workflows running
var flows = new Workflow().getRunningFlows(gr);
while(flows.next()) {
new Workflow().cancelContext(flows);
}
// attach the new context
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName('give the workflow name'), gr, 'update');
}
}
catch(ex){
gs.info('Exception'+ex);
}
})();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 04:37 AM
Hi Dharani,
Please use Nudge button to start the hung workflow under workflow context.
Please mark the response as Helpful/Correct, if applicable. Thanks!
Thanks,
Nikita

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 04:40 AM
Hi Dharani,
You can try using below in background script.
var gr = new GlideRecord('sc_req_item');//pass table name accordingly
gr.get('<syd_id_of_record>'); //sys_id of record for which workflow has to be restarted
var workflow = new Workflow();
workflow.cancel(gr);
var newWorkflow = new Workflow();
newWorkflow.startFlow(new Workflow().getWorkflowFromName('<Workflow name here>'), gr, '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 04:52 AM
you can use this script in background for your table record to delete older context and attach new workflow context
(function(){
try{
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('YOUR QUERY HERE'); // PASS your QUERY HERE
gr.query();
while(gr.next()){
// cancel old workflows running
var flows = new Workflow().getRunningFlows(gr);
while(flows.next()) {
new Workflow().cancelContext(flows);
}
// attach the new context
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName('give the workflow name'), gr, 'update');
}
}
catch(ex){
gs.info('Exception'+ex);
}
})();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 05:13 AM
Hi Ankur,
I tried the below script, but still approval activity in workflow is getting skipped. But the approval was approved by the user.
(function(){
try{
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('numberSTARTSWITHRITM0029578'); // PASS your QUERY HERE
gr.query();
while(gr.next()){
// cancel old workflows running
var flows = new Workflow().getRunningFlows(gr);
while(flows.next()) {
new Workflow().cancelContext(flows);
}
// attach the new context
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName('IT-User Support'), gr, 'update');
}
}
catch(ex){
gs.info('Exception'+ex);
}
})();