Can you order the result from "orderByAggregate('COUNT')" by ascending instead of the default descending?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 06:21 AM
Hello. I have a script that counts incidents that have "assigned_to" value, and then groups them by "assigned_to" value.
After that I sort the result with "orderByAggregate", but the default result is sorted by "desc". Is there any possible way to sort the result by "asc", so that I get the lowest value first? Thanks.
var count = new GlideAggregate('incident');
count.addEncodedQuery(aggregateQuery); // Query for specific user/s
count.addAggregate('COUNT');
count.groupBy('assigned_to');
count.orderByAggregate('COUNT');
count.query();
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 06:29 AM
HI,
count.orderByAggregate('COUNT'); Instead of this use
agg.orderByAggregate('count','assigned_to');
Thanks,
Ashutosh Munot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 06:39 AM
I have tried this, but I get this error:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 06:49 AM
HI,
See below script which is works:
var agg2 =new GlideAggregate('incident'); agg2.addAggregate('count','category'); agg2.orderByAggregate('count','category'); agg2.orderBy('category'); agg2.addQuery('opened_at','>=','javascript:gs.monthsAgoStart(3)'); agg2.addQuery('opened_at','<=','javascript:gs.monthsAgoEnd(3)'); agg2.addEncodedQuery(query); agg2.query(); var last =""; while(agg2.next()){ last = agg2.getAggregate('count','category');} gs.log(category +": Last month:"+ count +" Previous Month:"+ last); }
Thanks,
Ashutosh Munot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 07:32 AM
I don't see a descending order method. What I'd do is store the results in an array and then sort them that way before printing them out.