How can we close RITM when all the catalog task is closed for that item?

Surbhi16
Tera Contributor

Hi All,

How can I close the RITM when all the catalog task are changes to closed using business rule

Thanks
Surbhi

1 ACCEPTED SOLUTION

@Surbhi 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@Surbhi 

you can use after update BR on sc_task

Condition: State [IS ONE OF] Closed Complete/Closed Incomplete AND Request Item.Item == Your Catalog Item

Script:

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

	// Add your code here
	var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item', current.request_item); 
	gr.addQuery('active', true);
	gr.query();
	if(!gr.next()){
		var ritm = current.request_item.getRefRecord(); 
		ritm.state = 3;
		ritm.update();
	}

})(current, previous);

Regards
Ankur

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

@Surbhi 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

Mahendra RC
Mega Sage

Hello Surbhi,

Please check with below script in your after BR on sc_task table :

put Condition as State changeTo Close complete or Close incomplete
But check what you need to do when state is close incomplete

var grCatTask = new GlideRecord('sc_task');
grCatTask.addQuery("request_item=" + current.getUniqueValue() + "^state!=3");
grCatTask.query();
if(!grCatTask.haNext()){
      var grItem=new GlideRecord('sc_req_item');
      if (grItem.get(current.getValue("request_item")) {
        grItem.state=3;
        grItem.update();
}

Please mark this as helpful/correct, if it answer your question.

Thanks

Hello Surbhi,

Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.

If you still need any further help or guidance on this then please update those on this question.

Thanks

Rohit Sarkar1
Mega Guru

You can try the below logic putting the when to run condition as state is one of closed complete / incomplete an after BR on sc_task table

var gItem = new GlideRecord('sc_task');
	gItem.addQuery('request_item', current.request_item); 
	gItem.addQuery('active', true);
	gItem.query();
	if(!gItem.next()){
		var ritm = current.request_item.getRefRecord(); 
		ritm.state = 3;
		ritm.update();
	}