- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 03:24 AM
Hi,
I am currently working on Request, RITM and Catalog Task.
I have got a requirement to close the parent RITM when all the child Catalog Tasks are complete and also need to close the parent Request record when all the child RITM's are complete.
Could someone please let me know what needs to be done here. I know I need to script a BR here but not sure what to put in there.
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 05:12 AM
Hi,
Try below code:
// If you have more than one RITM for REQ then Use this Code.
var getRITM = new GlideRecord('sc_req_item');
getRITM.addActiveQuery();
getRITM.addQuery('request',current.request);
getRITM.query();
if(getRITM.next())
{
//DO whatever you want to do here;
//Dont close REQ as One of the RITM Is open.
gs.addInfoMessage('REQ cant be closed because one of the RITM is Open');
}
else
{
var req = new GlideRecord('sc_request');
req.addQuery('sys_id',current.request);
req.query();
if(req.next())
{
req.req_state = 'closed_complete';
req.update();
}
}
Thank you,
Ashutosh Munot
Please Mark Correct, Helpful or Like.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 04:26 AM
Hi Prudhvi,
Paste below code:
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.request_item);
gr.addActiveQuery();
gr.query();
if(gr.next())
{
current.setAbortAction(true);
}
else
{
var rit = new GlideRecord('sc_req_item');
rit.addQuery('sys_id',current.request_item);
rit.query();
if(rit.next())
{
rit.state = 3;
rit.update();
}
}
Thank you,
Ashutosh Munot
Please Hit Correct, Helpful or like,if you are satisfied with this response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 05:02 AM
Hi Ashutosh,
It worked for Catalog Tasks. Whenever I close all tasks, the RITM gets closed. But, whenever all RITM are closed, the Request is not moving to Closed Complete.
I have created a BR on RITM table and pasted ur code. However, I have changed a line in your code for closing request.
In your code, i changed the below line:
rit.state = 'closed_complete';
TO
rit.req_state = 'closed_complete';
Because, when I right-clicked the field, it showed "req_state"
Below is the screenshot:
Anything else missing Ashutosh? Please let me know.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 05:06 AM
Hi,
Please mark answer as helpful or correct.
Now Your REQ has more RITM's?
If yes, then i will have to change some code.
Will paste in 5mins.
Thank you,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 05:07 AM
Yes Ashutosh. My Request has many RITMs. Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 05:12 AM
Hi,
Try below code:
// If you have more than one RITM for REQ then Use this Code.
var getRITM = new GlideRecord('sc_req_item');
getRITM.addActiveQuery();
getRITM.addQuery('request',current.request);
getRITM.query();
if(getRITM.next())
{
//DO whatever you want to do here;
//Dont close REQ as One of the RITM Is open.
gs.addInfoMessage('REQ cant be closed because one of the RITM is Open');
}
else
{
var req = new GlideRecord('sc_request');
req.addQuery('sys_id',current.request);
req.query();
if(req.next())
{
req.req_state = 'closed_complete';
req.update();
}
}
Thank you,
Ashutosh Munot
Please Mark Correct, Helpful or Like.