Emails on Request Table with Multiple RITMS

terrieb
Tera Guru

So we are pushing the "Cart" option on the employee portal which creates multiple RITMS, which is all good.

 

The issue we are having that as soon as the first RITM is closed complete, the Request goes to Closed Complete state and it sends out the Request Complete emails to ALL the RITM requested for, even if the other RITMS are still Open.

 

Is there a way to fix this behavior so it doesn't send out the Request is Completed until ALL the RITMS linked to it are closed?

 

Thanks!

9 REPLIES 9

Ankur Bawiskar
Tera Patron

@terrieb 

so 1 REQ has multiple RITMs?

the OOTB BR doesn't check if that REQ has multiple RITMs

So approach

1) deactivate that OOTB BR and create after update on RITM which checks if this is the last RITM under this REQ which is getting closed, if yes then close REQ

check below link for sample logic for script

Business Rule to close Parent REQ when all RITM is closed 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@terrieb 

Just a quick follow-up—were you able to review the links above and try the suggested approach?
Please let me know if you need any assistance.

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

No it didn't work.  I tried 2 sets - one where I closed the RITM that did not have the Request populated with the description of it (populated the 2nd RITM's SD instead) and one where I closed the 2nd RITM first. 

 

Results were the same.

Tanushree Maiti
Tera Patron

Hi @terrieb 

 

By default, ServiceNow relies on a OOB Business Rule called Close Parent if required. As soon as any Requested Item (RITM) closes, this rule fires. 

It checks if any other RITMs under the same Parent Request (REQ) are still open. 

OOB, this rule evaluates to true too quickly, closing the parent REQ and firing the "Request Complete" notification, even if other RITMs are still active.

Ref the solution section: KB0687501 Request still open even after the Requested Item and the sc_task are closed 

 

Probable Solution: Update the "Close Parent if required" Business Rule

 

Sample code:

(function executeRule(current, previous /*null when async*/) {
var ritmObj = new GlideRecord('sc_req_item');
ritmObj.addQuery('request', current.request);
ritmObj.addQuery('sys_id', '!=', current.sys_id);
ritmObj.addActiveQuery();
ritmObj.query();
if (!ritmObj.next()) {
var reqObj = new GlideRecord('sc_request');
reqObj.addQuery('sys_id', current.request);
reqObj.addActiveQuery();
reqObj.query();
if (reqObj.next()) {
reqObj.request_state = 'closed_complete';
reqObj.update();
}
}
})(current, previous);
 
 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

The  1-1 rule (1 Req/1 RITM) I have no issues with those as they are linked to the flow for the RITM.

 

My issue is people using the Cart method to order multiple items at one time and the Request is populating the Short Description based on the LAST RTM created.  So as soon as the LAST RITM is closed, whether it's closed first, somewhere in the middle or NOT Last, the Request closes and it sends out a Request Closed email for every RITM item, most of which are still open, not closed.

 

I tried turning inactive the OOB BR for Close Parent if Required, and created the new BR from the link Ankur put in this question, but that didn't work either