**GlideAggregate SUM Returning Unexpected Multiple Outputs in Background Scripts**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi everyone,
I am currently learning GlideAggregate and trying to use the SUM aggregate on the Incident table.
I used the below script in Background Scripts:
var ga = new GlideAggregate("incident");
ga.addAggregate("SUM", "reassignment_count");
ga.query();
if (ga.next()) {
var total = ga.getAggregate("SUM", "reassignment_count");
gs.info(total);}
The field reassignment_count is an Integer type field. However, sometimes I am getting the output as 0.
If I use while(ga.next()) instead of if(ga.next()), then I get outputs like:
0
21
18
3
I am wondering whether old Background Scripts or grouped results are also getting executed along with my current script.
Can anyone please explain why this is happening and how to properly test GlideAggregate SUM in Background Scripts?
Thanks in advance.