How to close request if ALL Request Items are closed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 10:26 AM - edited 03-08-2024 10:31 AM
Hi Everyone,
We have a catalog item that creates a Request that contains a Request Item with tasks. Currently when all the tasks are completed the Request Item will close and then the Request will close. That part is working great. However, users can add multiple requests items to the request. In these examples, ALL request items and tasks should be closed before the request is closed. Attached is the flow used and the most recent business rule. In addition, we have the oob business rule Close Parent if Required active and I was curious if this needed modified?
Any suggestions on how to best achieve this.
Thanks in advance for any feedback you can provide
this or if this is even possible?
Thanks in advance for any feedback you can provide!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 12:10 PM
Due to the Add to Cart and Order Guide functionality, creating multiple RITM records under the same REQ is common out of the box. The OOTB Business Rule Close Parent if Required also handles not closing the REQ until all of the RITMs are inactive. Does your BR script contain only this line?
new SNC.RequestItem(current).closeParentRequest();
This SI is hidden, so it couldn't have been easily altered in your environment. Do you have any other Business Rules on the sc_req_item table that are prematurely closing the REQ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 12:46 PM - edited 03-08-2024 12:48 PM
@Brad Bowman thank you for your feedback and help! The OOTB Business Rule Close Parent if Required does contain the line you mentioned. Attached is a copy of everything for that business rule. I did search for other request item business rules and we do have one to set request closed...Can you look at the attached Set Request Closed if Req Item closed screenshots as I am curious if this script is causing the conflict.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2024 04:54 AM
Yes, your Business Rule name Set Request Closed if Req Item closed is always closing the REQ when (any) RITM is closed. First try inactivating this Business Rule to see if everything works fine using only the out of the box BR/Script Include. If the REQ is not getting closed in a certain test case for some reason, you would want your script in this BR to look more like this to check if there are any other open RITM records for the same REQ before closing the REQ.
(function executeRule(current, previous /*null when async*/) {
//first see if there are any active RITMs, excluding the current record, with this same REQ
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.request);
ritm.addQuery('sys_id', '!=', current.sys_id);
ritm.addActiveQuery();
ritm.query();
//if there are not, and the REQ is still open, close it
if (!ritm.next()) {
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id', current.request);
gr.addActiveQuery();
gr.query();
if (gr.next()) {
gr.request_state = 'closed_complete';
gr.update();
}
}
})(current, previous);