- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 04:23 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 09:58 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2015 05:11 AM
Thank you Berny. Sometimes it just takes that extra set of eyes to see the foolish mistake.