Auto close SC task once approvals are approved on RITM

Poorva Bhawsar
Mega Sage

Hi Community,

 

I want to auto close SC task once approval on ritm is approved. I have a workflow which is auto closing RITM once SC task is set to closed complete.

 

Thanks,

Poorva Bhawsar

2 ACCEPTED SOLUTIONS

shloke04
Kilo Patron

Hi @Poorva Bhawsar ,

Add an condition after your approval activity block as shown below:

 

1.Add a Run Script activity block connecting your approval step and then set the state of the catalog task to closed complete :

shloke04_0-1707202627464.png

Script to be used inside Run Script in above diagram:

closeTask();

function closeTask(){
	var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item',current.sys_id);
	gr.query();
	while(gr.next()){
		gr.state = 3;
		gr.update();
	}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

Aniket Chavan
Tera Sage
Tera Sage

Hello @Poorva Bhawsar ,

You can achieve this with your existing workflow itself, Simply insert a "Run Script" activity immediately following the approval step, connecting it to the approval's approved output. This ensures that the script runs only when the approval is successfully approved. Within the "Run Script" activity, incorporate the following code:

 

 

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state', '!=', 3);  //3 is closed complete value of Sc task
gr.query();

while (gr.next()) {
    gr.setValue('state', 3);
	gr.assigned_to = 'd4fdf4b7dbe01f00d27a00b5ca96195a'; //set the catalog task fields which are mandatory while close completing the task.
    gr.update();
}

 

AniketChavan_0-1707202867381.png

 

AniketChavan_1-1707203227678.png

 

 

I have Tested the above code and other functionality from my end and its working as expected.

 

Please le me know your views and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi @Poorva Bhawsar ,

Add an update action with Flow Designer and set the RITM stage to Completed. This will trigger business rules to close the RITM and the Request.

 

I have workflow instead of flow. I want to set sc task as closed complete once approvals are approved on ritm.

shloke04
Kilo Patron

Hi @Poorva Bhawsar ,

Add an condition after your approval activity block as shown below:

 

1.Add a Run Script activity block connecting your approval step and then set the state of the catalog task to closed complete :

shloke04_0-1707202627464.png

Script to be used inside Run Script in above diagram:

closeTask();

function closeTask(){
	var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item',current.sys_id);
	gr.query();
	while(gr.next()){
		gr.state = 3;
		gr.update();
	}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Aniket Chavan
Tera Sage
Tera Sage

Hello @Poorva Bhawsar ,

You can achieve this with your existing workflow itself, Simply insert a "Run Script" activity immediately following the approval step, connecting it to the approval's approved output. This ensures that the script runs only when the approval is successfully approved. Within the "Run Script" activity, incorporate the following code:

 

 

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state', '!=', 3);  //3 is closed complete value of Sc task
gr.query();

while (gr.next()) {
    gr.setValue('state', 3);
	gr.assigned_to = 'd4fdf4b7dbe01f00d27a00b5ca96195a'; //set the catalog task fields which are mandatory while close completing the task.
    gr.update();
}

 

AniketChavan_0-1707202867381.png

 

AniketChavan_1-1707203227678.png

 

 

I have Tested the above code and other functionality from my end and its working as expected.

 

Please le me know your views and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket