Need some help with a GlideAggregate sum script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 06:30 AM
Hi SNC,
Case goes like this - I have a field on the problem form (u_total), that I want to be populated with the sum of the values from the field 'u_impacted_allocation' in each related to the problem incident. Below is my script which does not sum them up currently. What am I missing?
(function executeRule(current, previous /*null when async*/) {
var gr1 = new GlideAggregate('incident');
gr1.addQuery('problem_id', current.sys_id); //finds the outages for the incidents related to the current problem
gr1.addAggregate('SUM','u_impacted_allocation');
gr1.query();
while(gr1.next()){
var total = gr1.getAggregate('SUM','u_impacted_allocation'); //calculates the total proportional impact allocation
current.u_total = total; //sets the calculation to the field on the problem form
current.update();
}
})(current, previous);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 02:05 AM
I had similar issue and the group by fixed it. thanks mate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 08:53 AM
Off the top of my head - I don't think you can set values to fields inside of a GlideAggregate lookup. So one of the things I'd do is turn this:
while(gr1.next()){
var total = gr1.getAggregate('SUM','u_impacted_allocation'); //calculates the total proportional impact allocation
current.u_total = total; //sets the calculation to the field on the problem form
current.update();
}
into this:
while(gr1.next()){
var total = gr1.getAggregate('SUM','u_impacted_allocation'); //calculates the total proportional impact allocation
}
current.u_total = total; //sets the calculation to the field on the problem form
current.update(); //Since this is a business Rule only use this if this is an After or Async Business Rule.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 10:31 AM
You can set inside the GlideAggregate while/if loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 11:17 AM
Good to know.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 10:20 AM
What is the field type of impacted allocation and total?