Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Hi,

So it is adding new context but approval is getting skipped

Did you check any user is being set in that user approval activity?

Regards
Ankur

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

yes the approval triggered to user and user approved it earlier.

The earlier workflow context got cancelled and the new workflow context didn't trigger.

 

find_real_file.png

Hi,

can you share the script you are using as per what I shared?

Regards
Ankur

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

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

})();

Hi,

so is that not cancelling old and attaching new context?

Regards
Ankur

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