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

It is not changing the Request state to Closed Complete Ashutosh. All I did was adding your code. See below:



Screenshot (745).png


What is going wrong. Please let me know.


When to Run condition?



Thank you,
Ashutosh


Also paste screen shot of REQ. I think it will be already closed. Because RITM and REQ share different Workflow.



Thank you,


Ashutosh


This is the Request form I have been working on.



find_real_file.png


No Ashutosh. Where to write it?