How to get the count of the tasks for each RITM?

Sam Salameh
Mega Guru

Hi there,

How to get the count of all the tasks for each RITM and add the result in a custom field on the RITM?

I have created a Business Rule on the task table.

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

var edt = new GlideAggregate("u_engineering_data_tracker"); // Task table
    edt.addEncodedQuery("state!=3^u_property_location=" + current.u_property_location.sys_id); // add filter // u_property_location is the parent table (like RITM)
    edt.addAggregate("COUNT"); // add the count
    edt.query();

    if (edt.next())
        count = edt.getAggregate('COUNT'); // get the count <<< --- to here is working fine.
       current.u_property_location.u_task_count= count; <<< --- Not working.

// I'm trying to dot walk to copy the value to the parent table. 

})(current, previous);
6 REPLIES 6

Sam Salameh
Mega Guru

found this error in the system log: Invalid query detected, please check logs for details [Unknown field agile_story in table u_engineering_data_tracker]

Does this has anything to do with my issues?

Sample code to get task on Incident record

var edt = new GlideAggregate("incident"); // Task table
    edt.addEncodedQuery('parentLIKETAsk'); // add filter // parent field is the parent table referenced to task)
    edt.addAggregate("COUNT"); // add the count
    edt.query();

    while(edt.next()){
    count = edt.getAggregate('COUNT'); // get the count <<< --- to here is working fine.
gs.info(edt.getAggregate('COUNT'));
}

I have 2 tasks associated with 2 Incident. Each task for a incident

Regards
Harish