Close RITM when ALL related Change requests have been closed

FredrikT
Tera Guru

I have a Catalog Item using traditional workflow with multiple SCTASKs that eventually results in one or more related Change Requests being attached to the RITM.  I am trying to have the RITM close ONLY when ALL related Change Requests have been closed.  Currently using a Wait for condition in the workflow for "Wait for Change to Close" the RITM gets closed when the 1st related Change Requests is closed, not all of them.  Is there a better way?  Many suggest an after business rule however I have not found any examples that spell out what I need to do for my particular scenario.  

 

Thank you 

1 ACCEPTED SOLUTION

@FredrikT You can use the following script to add that check. You need to replace YOUR_CATALOG_ITEM_SYS_ID in the script with your catalog item sys_id.

 

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

    var gr = new GlideRecord("change_request");
    gr.addQuery("parent", current.parent.sys_id);
    gr.addEncodedQuery("stateNOT IN3,4");
    gr.query();
    if (!gr.hasNext()) {
        var ritmGr = new GlideRecord("sc_req_item");
        if (ritmGr.get(current.parent.sys_id)) {
            var cat_item_id = ritmGr.getValue('cat_item') + '';
            if (cat_item_id == "YOUR_CATALOG_ITEM_SYS_ID") {
                ritmGr.state = '3';
                ritmGr.stage = 'closed_complete';
                ritmGr.update();
            }
        }
    }

})(current, previous);

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh

View solution in original post

6 REPLIES 6

@FredrikT You can use the following script to add that check. You need to replace YOUR_CATALOG_ITEM_SYS_ID in the script with your catalog item sys_id.

 

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

    var gr = new GlideRecord("change_request");
    gr.addQuery("parent", current.parent.sys_id);
    gr.addEncodedQuery("stateNOT IN3,4");
    gr.query();
    if (!gr.hasNext()) {
        var ritmGr = new GlideRecord("sc_req_item");
        if (ritmGr.get(current.parent.sys_id)) {
            var cat_item_id = ritmGr.getValue('cat_item') + '';
            if (cat_item_id == "YOUR_CATALOG_ITEM_SYS_ID") {
                ritmGr.state = '3';
                ritmGr.stage = 'closed_complete';
                ritmGr.update();
            }
        }
    }

})(current, previous);

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

 

Thanks,
Anvesh

FredrikT
Tera Guru

Perfect! Thank you so much!