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 07:45 PM
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?

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