Script to update RITM state based on Catalog task state

Kaustubh k
Tera Expert

Hello All, 

 

The are multiple RITMs which is in open state even when the related catalog tasks is closed,

Could you please help with a BG/fix script to update all the RITM state to closed whose catalog tasks are closed

 

Please note : we have to only update those RITMs with state (open/pending/inprogress) but has related catalog tasks in Closed state.

 

 

 

 

1 ACCEPTED SOLUTION

Chetan Mahajan
Kilo Sage

Hello @Kaustubh k ,

                                                Refer below script, update values accordingly 

 

 

 // Script for multiple records closure
    var ritmGR = new GlideRecord('sc_req_item'); // table name
    ritmGR.addEncodedQuery("stateIN-5,1,2"); // filtered query
    ritmGR.query();

    while (ritmGR.next()) {

        // Query for related Catalog Tasks in the "Closed" state
        var relatedCatalogTasks = new GlideRecord('sc_task');
        relatedCatalogTasks.addQuery('request_item', ritmGR.sys_id);
        relatedCatalogTasks.addQuery('state', '3'); // closed complete
        relatedCatalogTasks.query();

        // If no Catalog Tasks found in "Closed" state, exit the script
        if (!relatedCatalogTasks.hasNext()) {
            return;
        }
// update RITM as closed complete
else {           
        ritmGR.setValue('state', '3'); // closed complete
        ritmGR.setWorkflow(false);
        ritmGR.update();
        gs.info("Record Updated " + ritmGR.number);
}
      
    }

 

Note : You can use count while checking task if Count of all attached task is equal to count of closed task then update RITM as closed complete

Kindly mark correct and helpful if applicable

View solution in original post

1 REPLY 1

Chetan Mahajan
Kilo Sage

Hello @Kaustubh k ,

                                                Refer below script, update values accordingly 

 

 

 // Script for multiple records closure
    var ritmGR = new GlideRecord('sc_req_item'); // table name
    ritmGR.addEncodedQuery("stateIN-5,1,2"); // filtered query
    ritmGR.query();

    while (ritmGR.next()) {

        // Query for related Catalog Tasks in the "Closed" state
        var relatedCatalogTasks = new GlideRecord('sc_task');
        relatedCatalogTasks.addQuery('request_item', ritmGR.sys_id);
        relatedCatalogTasks.addQuery('state', '3'); // closed complete
        relatedCatalogTasks.query();

        // If no Catalog Tasks found in "Closed" state, exit the script
        if (!relatedCatalogTasks.hasNext()) {
            return;
        }
// update RITM as closed complete
else {           
        ritmGR.setValue('state', '3'); // closed complete
        ritmGR.setWorkflow(false);
        ritmGR.update();
        gs.info("Record Updated " + ritmGR.number);
}
      
    }

 

Note : You can use count while checking task if Count of all attached task is equal to count of closed task then update RITM as closed complete

Kindly mark correct and helpful if applicable