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
04-24-2025 01:38 AM
Hi @Colleen
please try this -
var example = new GlideQuery('incident')
.where('sys_created_on', '>=', new GlideDateTime('2025-01-01 00:00:00'))
.groupBy('priority')
.aggregate('sum', 'reassignment_count')
.aggregate('count') // remove 'number' to count total records in each group
.having('sum', 'reassignment_count', '>', 4)
.select()
.toArray(100);
gs.print(JSON.stringify(example));
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 02:12 AM
Hi Tushar
Thanks for the prompt response. Apologies, my example script was not clear. I updated the script after posting, but you probably replied to the original script.
I want to base the having clause on the count. My understanding is that having needs to use the same field as the aggregate.
The results appear to return the correct information based on the having clause, even though the count is null.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 02:16 AM
check this link
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader