- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 07:09 AM
Hi Team,
I need to count the distinct number of requested approvals in the sysapproval_approver table.
Like as shown in the below screenshot, the total count of approvals in requested state is 60, but after GroupBy of the Approval For the result is 31. I am trying to achieve this by glideRecord but it's not working. Can you please assist.
var count = 0;
var gr = new GlideAggregate(‘sysapproval_approver’);
gr.addQuery (‘state’,’requested’);
gr.addAggregate('COUNT','sysapproval');
gr.orderByAggregate('COUNT','sysapproval');
gr.query();
if(gr.next())
count = gr.getAggregate('COUNT','sysapproval');
gs.print(parseInt(count));
Thanks in advance,
Sarah
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 08:25 AM
If you want the total number to be like when they are group by try using GlideRecord instead of GlideAggregate.
var count = 0;
var counted = [];
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery ('state','requested');
gr.query();
while(gr.next()) {
if (!counted[gr.sysapproval]){
counted[gr.sysapproval] = true;
count++;
}
}
gs.print(count);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 08:33 AM
This works Brian! Thanks a lot.
Regards,
Sarah