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 07:36 AM
Hey Chuck, my solution was kinda similar. I store them in Array and then I iterate backwards over that array.
Kinda weird that there is no "asc" ordering 🙂
Thanks! 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 05:28 AM
If you feel you need it, I invite you to open an enhancement request! Our product managers DO listen.
Enhancement requests: Tell us how you would improve the ServiceNow product
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 11:01 AM
I found this to work:
var count = new GlideAggregate('table_name');
count.addAggregate('COUNT');
count.groupBy("group_by_field");
count.orderByAggregate('count');
count.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 03:53 AM
Hello t_ivanov,
You can try.
count.orderByAescAggregate('COUNT');
thank you.