How to delete and attach a new workflow in the RITM

shaik_irfan
Tera Guru

Hi,

 

I have made changes to the existing workflow and deployed last week everything is fine but my manager wanted me to replace the new workflow to all the existing RITM's which are currently open. 

 

Can we do that?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will have to delete the older workflow running context for those RITMs

then using script attach the new workflow to that RITM

example

updateWorkflow();

function updateWorkflow(){

	try{

		var gr = new GlideRecord('sc_req_item');
		gr.addEncodedQuery('YOUR QUERY HERE'); // PASS your QUERY HERE
		gr.query();
		while(gr.next()){

			// delete old context
			var gr1 = new GlideRecord('wf_context');
			gr1.addQuery('id', gr.sys_id);
			gr1.query();
			gr1.deleteMultiple();

			// attach the new one
			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

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will have to delete the older workflow running context for those RITMs

then using script attach the new workflow to that RITM

example

updateWorkflow();

function updateWorkflow(){

	try{

		var gr = new GlideRecord('sc_req_item');
		gr.addEncodedQuery('YOUR QUERY HERE'); // PASS your QUERY HERE
		gr.query();
		while(gr.next()){

			// delete old context
			var gr1 = new GlideRecord('wf_context');
			gr1.addQuery('id', gr.sys_id);
			gr1.query();
			gr1.deleteMultiple();

			// attach the new one
			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

@shaik.irfan 

Hope you are doing good.

Did my reply answer your question?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Thanks!
Ankur

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

@shaik.irfan

Hope you are doing good.

Did my reply answer your question?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Thanks!
Ankur

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