Trying to close the Parent records when the Child records are closed

prudhvig
Tera Expert

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.

1 ACCEPTED SOLUTION

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.


View solution in original post

23 REPLIES 23

Pritam3
Giga Contributor

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();


}


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.


Ashutosh Munot1
Kilo Patron
Kilo Patron

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


Hi Ashutosh,



Thanks for the reply. I have tried using your code and it showed me some errors. Below is the screenshot:



Screenshot (743).png


Could u pls tell me what mistakes I am doing? Thanks in advance.