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

Shekhar Navhak1
Kilo Sage
Kilo Sage

Hi,

Can you please try below code

 

(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();

    while (edt.next()){
        count = edt.getAggregate('COUNT'); // get the count 
       }
       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);

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Regards,

Shekhar

Please mark the answer correct/helpful based on Impact.
Regards, Shekhar

    var edt = new GlideAggregate("u_engineering_data_tracker");
    edt.addEncodedQuery("state!=3^u_property_location=" + current.u_property_location.sys_id);
    edt.addAggregate("COUNT"); // add the count
    edt.query();

    while (edt.next()) {
        count = edt.getAggregate('COUNT');
        gs.addInfoMessage("count " + count);
    }
    current.u_property_location.u_task_count = count; //<<-- Not working
    gs.addInfoMessage("current.u_property_location.u_task_count " + current.u_property_location.u_task_count);

//addinfomessage is printing correct numbers but it's still not updating the custom field.

What value does the u_property_location hold? Task or RITM?

Regards
Harish

u_property_location is the reference field on the task.