If RITM state is closed complete then REQ should also closed complete

Shiva prasad t
Tera Guru

I need to update the REQ state to closed complete when RITM state is closed complete.

currently if state of sc_task is closed then RITM state is setting as closed complete.

So as well as RITM i need to closed Request also if RITM is closed.

Any help will be appreciated.

Thank you,

Shivprasad

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then add the logic there itself where you are closing RITM

update as this

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var closedCompleteCount = 0;
    var closedInCompleteCount = 0;
    var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.request_item); 
    gr.query();
    var totalCount = gr.getRowCount();
    while(gr.next()){
        if(gr.state == 3){
            closedCompleteCount++;
        }
        if(gr.state == 4){
            closedInCompleteCount++;
        }
    }

    var ritm = current.request_item.getRefRecord();
    var req = current.request.getRefRecord();
    if(totalCount == closedCompleteCount){
        ritm.state = 3;
        ritm.update();
        req.state = 3;
        req.update();
    }
    if(closedInCompleteCount > 0){
        ritm.state = 4;
        ritm.update();
        req.state = 3;
        req.update();
    }

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Musab Rasheed
Tera Sage
Tera Sage

Hello,

It should work by default, is it not working ?

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

No it's not working

Check if this BR in active ? should work OOB

https://instance/sys_script.do?sys_id=596fac6bc0a8010a00dca5b76857e592&sysparm_record_target=sys_script&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=active%3DTrue%5EnameSTARTSWITHClose+Parent+if+Required%5EORDERBYDESCsys_updated_on

Please hit like and mark my response as correct if that helps
Regards,
Musab

Yeah it is in active state only