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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 06:07 PM
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);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 06:26 PM
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
Regards, Shekhar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 07:00 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 07:40 PM
What value does the u_property_location hold? Task or RITM?
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 07:47 PM
u_property_location is the reference field on the task.