How to Use GlideAggregateRecord_Query for Aggregation in ServiceNow GraphQL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 07:34 AM
Hello Community,
I’m trying to use the GlideAggregateRecord_Query function in ServiceNow GraphQL to perform an aggregate query on the Problem table. My goal is to group the records by state and count the number of records in each group.
Here’s the query I attempted:
query {
GlideAggregateRecord_Query(
tableName: "problem",
queryConditions: "active=true",
groupBy: ["state"],
aggregateOptions: "COUNT,state",
orderBy: "state",
groupPagination: {
limit: 5,
offset: 0
}
) {
groups {
state
COUNT
}
totalCount
}
}
However, this query is not returning the expected results, and I’m unsure if I’m using the function parameters correctly. I’d appreciate guidance on the following:
- How should the aggregateOptions parameter be formatted for a COUNT operation?
- Is the groupBy parameter correctly specified as an array of field names?
- Are there specific configurations needed in ServiceNow for the GlideAggregateRecord_Query function to work?
- Can someone share a working example of GlideAggregateRecord_Query for any table?
If anyone has experience using this GraphQL query or can point me to additional resources, that would be greatly appreciated!
Thank you! 😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 12:25 AM
Try below query:
query {
GlideAggregateRecord_Query(
tableName: "problem",
queryConditions: "active=true",
groupBy: ["state"],
orderBy: "state",
groupPagination: { limit: 5, offset: 0 }
) {
aggregates{
count
groupBy{
field
value
displayValue
}
}
groupColumnLabel
totalCount
}
}
If this query resolves your issue, please consider marking this response as helpful and voting for it. It will assist others facing similar issues! 😊