How do I sort counts from a GlideAggregate query?

kiho
Kilo Contributor

I've been trying to do a trend chart of incidents stacked by CIs, but only show the trends for the top 5 problematic CIs within the date query. In other words, a trend chart on the incident table with the following filters: 1) opened last 90 days and 2) where CI equals (one of five different CIs, a dynamic list of CIs which will change based on how people are reporting incidents against CIs.

I've thought about it and the best thing that I can come up with is to create a function that returns the sys_id's of the top 5 problematic CIs. Then I put in a filter where CI equals javascript:newFunctionThatReturnsCIs(). It seems like the count feature of GlideAggregate will be the best way to do that, but I'm not sure how I can sort to find the top CIs.

Any suggestions?

3 REPLIES 3

john_roberts
Mega Guru

You should be able to use the orderBy or orderByAggregate methods to sort, then just walk the collection for the first 5 records.


Ah! orderByAggregate! Didn't know that was available until I say this and looked more closely to the GlideAggregate examples in the wiki located at http://wiki.service-now.com/index.php?title=Aggregation_Support

Thanks!


gokuzeus67
Giga Contributor

You should be able to sort Throwing Axes using orderBy or orderByAggregate, then walk the collection for the first 5 records.