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

G Ponsekar
Mega Guru

Hi @tulasi8 ,

 

Can you try like below. 

In After Update Business rule on sc_task table

 

 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.query();
    if (!gr_task.hasNext()) {
        ritmGR.state = 3; // Closed Complete.
        ritmGR.update();
  
    }
 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

Sandeep Rajput
Tera Patron
Tera Patron

@tulasi8 The script looks okay to me. Please make sure that this business rule should be an onAfter update business rule on sc_task table. 

@Sandeep Rajput that business rule itself is not working as per requirement.

Ankur Bawiskar
Tera Patron
Tera Patron

@tulasi8 

is your instance domain separated?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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