Closing a Request only when all the corresponding Requested Items are moved to closed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 03:41 AM
Hi,
I am working on the Request (Service Catalog) applciation in Servicenow.
Currently, in my instance:
1. Requested Items can be closed only when it's catalog tasks are moved to Complete.
2. In the same way, Requests are also being closed when catalog tasks are Complete, but do not wait for the attached Requested Items to get completed.
I want the Request to be completed only when the corresponding RITMs are closed. How can I achieve that? Does Servicenow provide any out-of-the-box BR or client script to handle this?
Please let me know. Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 04:15 AM
Hi,
There is an OOB BR named "Close Parent if Required".
This Br will close the REQ automatically when all the RITMS are closed.
You can modify that according to your requirement
or
You can create a BR on ritm table as follows
closeREQ();
function closeREQ(){
var req = new GlideRecord('sc_request');
req.addQuery('active', true);
req.query();
while (req.next()) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('active', true);
ritm.addQuery('request',req.sys_id);
ritm.query();
if (ritm.hasNext()) {
//if not closed abort the action
current.setAbortAction(true);
gs.addErrorMessage("Please close the RITM before closing the request");
}
else {
req.state = '3'; // closed
req.update();
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 04:36 AM
I have updated my BR
Check this
Run the BR on sc_request table as follows
Here is the script
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('active', true);
ritm.addQuery('request',current.sys_id);
ritm.query();
if (ritm.hasNext()) {
//if not closed abort the action
current.setAbortAction(true);
gs.addErrorMessage("Please close the RITM before closing the request");
}
else {
current.state = '3'; // closed
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 06:00 AM
@Aakash Shah4
Your script automatically closed the RITM associated to the Req.
Was it working for you?