Aggregate Table Statistics
servicenow_aggregateCalculate COUNT, SUM, AVG, MIN, or MAX on ServiceNow tables, optionally grouped by a field, using server-side aggregation.
Instructions
Calculate COUNT, SUM, AVG, MIN, or MAX on any ServiceNow table — optionally grouped by a field.
Uses the ServiceNow Aggregate API (/api/now/stats) for efficient server-side aggregation without fetching records.
Args:
table (string): Table to aggregate (e.g., incident, change_request, cmdb_ci)
query (string): Filter query (e.g., 'state!=7', 'priority=1^assignment_group=SYS_ID')
count (boolean): Include total record count (default: true)
sum_fields (string): Comma-separated numeric fields to sum (e.g., 'resolve_time,business_duration')
avg_fields (string): Comma-separated numeric fields to average
min_fields (string): Comma-separated fields to find minimum
max_fields (string): Comma-separated fields to find maximum
group_by (string): Field to group by (e.g., 'state', 'priority', 'assignment_group', 'category')
having (string): HAVING clause for grouped results (e.g., 'COUNT>5')
response_format: Output format
Examples:
Count open incidents by priority → table="incident", query="state!=7", group_by="priority"
Average resolve time for P1s → table="incident", query="priority=1^state=7", avg_fields="resolve_time"
Total open incidents by group → table="incident", query="state=1^ORstate=2", count=true, group_by="assignment_group"
Incidents per day this week → table="incident", query="opened_atRELATIVEGE@week@ago@1", group_by="opened_at"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Include record count | |
| query | No | Encoded ServiceNow query string (e.g., 'state=1^priority=1^assigned_to=javascript:gs.getUserID()'). Leave empty to return all records. | |
| table | Yes | ServiceNow table name (e.g., incident, change_request, sys_user) | |
| having | No | HAVING clause for grouped results (e.g., 'COUNT>5') | |
| group_by | No | Field to group results by (e.g., 'state', 'priority') | |
| avg_fields | No | Comma-separated numeric fields to average | |
| max_fields | No | Comma-separated fields to find maximum | |
| min_fields | No | Comma-separated fields to find minimum | |
| sum_fields | No | Comma-separated numeric fields to sum | |
| response_format | No | Output format: 'markdown' (default) for human-readable or 'json' for structured data | markdown |