- 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 03:49 AM
write below code in after business rule:
var req=new GlideRecord('sc_req_item');//or sc_request
req.addQuery('parent',current.sys_id);
req.query();
while(req.next())
{
req.state=current.state;
req.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 04:07 AM
Hi pritam,
Thank for the reply. I have one doubt with your code. may I know how this would move the RITM or Request to Complete state? Because, I dont see anything in the code which checks whether all the RITMs or Catalog tasks are moved to Complete. And,I don't see anything that would move the code to CLosed COmplete state also. Am I missing something? Please let me know.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 04:05 AM
Hi,
You will require two business rules.
One on sc_task and one on sc_req_item.
1) On sc_task you have after update BR as below condition is state changes to Closed
//Check any active task on current RITM
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();
}
}
2) On RITM write below business rule: COndition will be state changes to Closed Complete
var rit = new GlideRecord('sc_request');
rit.addQuery('sys_id',current.request);
rit.query();
if(rit.next())
{
rit.state = 'closed_complete';
rit.update();
}
Thank you,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 04:22 AM