This widget could not be displayed.
This widget could not be displayed.

Restart Workflow for RITM

Dharani2
Kilo Contributor

Need to restart the workflow.

Approval got skipped somehow and workflow is struck. Please let me know how to restart.

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Dharani 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Nikita30
Mega Sage

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

 

 

 

Jaspal Singh
Mega Patron

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, '');

Ankur Bawiskar
Tera Patron

@Dharani 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

})();

 

find_real_file.png