Ritm should close once all sctasks are closed

tulasi8
Tera Contributor

Hi Community,

 

Here for single RITM, we do have many SCTASKs. So, RITM should get closed only once all tasks are closed. We are doing this in client domain in flow designer. But it's not working. Can anyone please help on this.

 

BUSINESS RULE : 


var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addQuery('active', true);
gr.query();
if (!gr.next()) {
    var ritm = current.request_item.getRefRecord();
    ritm.state = 3;
    ritm.update();
}

 

Regards,

Tulasi.

5 REPLIES 5

Juhi Poddar
Kilo Patron

Hello @tulasi8 

Please refer to the steps below:

  • Configuration setup for business ruleJuhiPoddar_0-1752596091945.png

     

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

    var ritmGR = current.request_item.getRefRecord();
    var gr_task = new GlideRecord('sc_task');
    gr_task.addQuery('request_item', ritmGR.sys_id);
    gr_task.addQuery('active', 'true');
    gr_task.addEncodedQuery("stateNOT IN3,4,7"); //closed complete, incomplete and skipped
    gr_task.query();
    if (!gr_task.hasNext()) {
        ritmGR.state = 3; // Closed Complete.
        ritmGR.update();
    }
})(current, previous);​

This Business Rule ensures that the associated Requested Item (RITM) is automatically closed once all active tasks are completed.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar