Parent REQs need to be closed when the child RITMs are not open

divyadhanda
Mega Guru

I want to write a fix script to update the parent Req is open when child RITMs/Sctasks are not open (Cancelled, Closed incomplete, closed complete).

7 REPLIES 7

Please check and let me know if this is correct.
var req = new GlideRecord('sc_request');
req.addQuery('active', true);   
req.addQuery('state', 1);      
req.query();
while (req.next()) {
      var ritm = new GlideAggregate('sc_req_item');
    ritm.addQuery('request', req.sys_id);
    ritm.addQuery('state', 1);  
    ritm.addAggregate('COUNT');
    ritm.query();
    if (ritm.next() && ritm.getAggregate('COUNT') > 0)
        continue;
   
    var task = new GlideAggregate('sc_task');
    task.addQuery('request_item.request', req.sys_id);
    task.addQuery('state', 1);  // SCTASK Open
    task.addAggregate('COUNT');
    task.query();
    if (task.next() && task.getAggregate('COUNT') > 0)
        continue;
 
    gs.print('REQ eligible to close: ' + req.number);
}

Hi @divyadhanda 

 

Yes, the script is correct. The logic properly checks for open RITMs and open Catalog tasks under the request. And you can also add the update logic later once validate the printed eligible REQs

 

Thanks 

Dimple Shaik

@divyadhanda 

that's what the script I shared is doing.

Did it not work for you in DEV?

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