GlideQuery aggregate count null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 01:32 AM - edited 04-24-2025 01:42 AM
Why is this GlideQuery returning count: null ?
var example = new GlideQuery('incident')
.where('sys_created_on', '>=', new GlideDateTime('2025-01-01 00:00:00'))
.groupBy('priority')
.aggregate('count', 'number')
.having('count', 'number', '>', 1)
.select().toArray(100);
gs.print(JSON.stringify(example));
Result:
[{"group":{"priority":0},"count":null},{"group":{"priority":1},"count":null},{"group":{"priority":2},"count":null},{"group":{"priority":3},"count":null},{"group":{"priority":4},"count":null}]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Running into this as well. I can't use count() for the having clause (which feels like a bug) and I can't use count(<field>) for the count because it's returned as null (also feels like a bug).
That said, in case somebody else stumbles across this, I found that ALSO adding a count() aggregate seems to get the job done. You can use the count(number) agg for the having the clause and the count() agg to actually get the count in the results. But I think that's only helpful if you're just counting records and not actually counting a non-unique field.
Not sure if GlideQuery is maintained, but this seemingly-buggy functionality has evidently been around for a while now.
