need to close RITM after all sc_tasks are completed

Vani14
Tera Contributor

For one RITM, we built two sc_tasks. When I try to close one sc_task, RITM closes but another sc_task remains open. Can somebody assist me in closing all sc_tasks before RITM closes?

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Vani14 

you can use after update BR on sc_task with proper conditions for State value

Condition: State [IS ONE OF] Closed complete, Closed incomplete, Closed skipped

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	
	// check if there is no active task for this RITM
	
	var gr = new GlideRecord("sc_task");
	gr.addActiveQuery();
	gr.addQuery("request_item", current.request_item);
	gr.setLimit(1);
	gr.query();
	if (!gr.hasNext()) {
		var ritm = current.request_item.getRefRecord();
		ritm.state = 3;
		ritm.update();
	}

})(current, previous);

OR

you can also use Flow designer with no script for this

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

@Vani14 

please use script I shared above.

sharing again with some changes

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	
	// check if there is no active task for this RITM
	
	var gr = new GlideRecord("sc_task");
	gr.addActiveQuery();
	gr.addQuery("request_item", current.request_item);
	gr.setLimit(1);
	gr.query();
	if (!gr.hasNext()) {
		var ritm = current.request_item.getRefRecord();
		ritm.state = current.state;
		ritm.update();
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

7 REPLIES 7

Hi @Ankur Bawiskar ,
its not working when i close one task its automatically closing RITM, another task is in open state.

@Vani14 

share your BR configuration screenshot and latest script

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

i did a mistake script is working thank you.