Glide Aggregate SUM not summing

donaldbates
Kilo Contributor

This should be super simple, but I'm missing it. I'm merely trying to count the chats from a customer table. The field in question is set as an integer. In this first section of code I would typically use an if instead of a while, but using the while to show how it's grouping the results. The second section of code is just so you can see what the actual record contains. The answer should be 3 when I sum. I followed Count and Sum and Avg and Min and Max, Oh My! as my example along with the wiki.

<!--BEGIN Find number of agents are on chats-->

var sc = new GlideAggregate('u_chat_round_robin');

sc.addAggregate('SUM', 'u_currentchats');

sc.addQuery('u_chat_queue', 'f03232f96f794e00c5afbd5dbb3ee4ed');

sc.query();

sc.setGroup(false);

var nc = 0;

while (sc.next()) {

nc = sc.getAggregate('SUM', 'u_currentchats');

gs.print('Number of chats ' + nc);

}

<!--END Find number of agents are on chats-->

<!--BEGIN Find number of agents are on chats-->

var sc = new GlideRecord('u_chat_round_robin');

sc.addQuery('u_chat_queue', 'f03232f96f794e00c5afbd5dbb3ee4ed');

sc.query();

var numberofchats = 0;

while (sc.next()) {

gs.print(sc.u_currentchats);

}

<!--END Find number of agents are on chats-->

RESULTS

*** Script: Number of chats 0

*** Script: Number of chats 1

*** Script: Number of chats 2

*** Script: 0

*** Script: 2

*** Script: 0

*** Script: 1

*** Script: 0

*** Script: 0

*** Script: 0

*** Script: 0

*** Script: 0

*** Script: 0

*** Script: 0

1 ACCEPTED SOLUTION

Thanks Donald, i now understand what's you're trying to accomplish and I believe i was able to see what we have wrong .



You just need to include the sc.setGroup(false); before the sc.query();



var sc = new GlideAggregate('u_chat_round_robin');


sc.addAggregate('SUM', 'u_currentchats');


sc.addQuery('u_chat_queue', 'f03232f96f794e00c5afbd5dbb3ee4ed');


sc.setGroup(false);


sc.query();


var nc = 0;


while (sc.next()) {


  nc = sc.getAggregate('SUM', 'u_currentchats');


  gs.print('Number of chats ' + nc);


}


View solution in original post

5 REPLIES 5

Thank you Berny. Sometimes it just takes that extra set of eyes to see the foolish mistake.