ServiceNow Statistics
In this article
Overview
You can use this to compute aggregate statistics — count, sum, average, min, max over a ServiceNow table using the Stats API (/api/now/stats/{table_name}), without pulling individual records.
Prerequisites
A valid ServiceNow account configured in SnapLogic.
The ServiceNow instance must support the Aggregate (Stats) API (Paris release or later).
At least one aggregate parameter must be provided in Query Parameters. Supported aggregate parameters are:
sysparm_count,sysparm_avg_fields,sysparm_sum_fields,sysparm_min_fields, orsysparm_max_fields. A request without at least one of these parameters is rejected by ServiceNow with a 400 error.
Supported Account Types
ServiceNow Account (Basic Auth)
ServiceNow OAuth2 Account
ServiceNow Dynamic Account
Support for Ultra Pipelines
Works in Ultra Pipelines.
Known Issues
None.
Snap Views
View | Description |
|---|---|
Input | Optional. Accepts 0–1 input documents. When an input document is present, expression-enabled fields in Query Parameters can reference values from the upstream document. |
Output | Produces one output document per input document containing the Stats API result as-is. For ungrouped queries, the output contains a single stats object (for example, When an input document is present, the original input is included under an |
Error | Error handling is a generic way to handle errors without stopping the Snap execution. You can handle errors by connecting the error view to a downstream target. Common errors include: invalid table name (404), missing aggregate parameter (400), authentication failure (401), and insufficient permissions (403). The error document includes the ServiceNow error text in the reason field. |
Snap Settings
Expression : JavaScript syntax to access SnapLogic Expressions to set field values dynamically (if enabled). If disabled, you can provide a static value. Learn more.
SnapGPT : Generates SnapLogic Expressions based on natural language using SnapGPT. Learn more.
Suggestion : Populates a list of values dynamically based on your Account configuration.
Upload : Uploads files. Learn more.
Learn more about the icons in the Snap Settings dialog.
Field Name | Field Type | Description |
|---|---|---|
Label* | String | The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline. |
Table name* | String | The name of the ServiceNow table to query. Suggestions load from the connected instance. This field does not support expressions. |
Query parameters | Table | A key-value table of query parameters to send to the Stats API. Each row has a Parameter name and Parameter value. Rows with a blank name are skipped. A blank value is still sent (for presence-only options such as |
Number of retries | Integer | Specify the maximum number of attempts the Snap makes to reconnect to the ServiceNow instance if the initial connection attempt fails, before it stops execution and displays an error. |
Retry interval (seconds) | Integer | Specify the number of seconds the Snap waits between each retry attempt. |
Snap Execution Default Value: Validate & Execute | Dropdown list | Select one of the following three modes in which the Snap executes:
|
Examples
Example 1: Simple Count
Configuration:
Parameter Name | Parameter Value |
|---|---|
|
|
Table name: incident
Output:
{
"stats": {
"count": "42"
}
}Example 2: Multiple Aggregations
Configuration:
Parameter Name | Parameter Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
Output:
{
"stats": {
"count": "42",
"avg": {"reassignment_count": "2.35"},
"sum": {"reassignment_count": "99"},
"min": {"reassignment_count": "0"},
"max": {"reassignment_count": "8"}
}
}Limitations
The Table name field does not support expressions.
At least one aggregate parameter (
sysparm_count,sysparm_avg_fields,sysparm_sum_fields,sysparm_min_fields, orsysparm_max_fields) is required. Sending a request without one results in a 400 error from ServiceNow.The
sysparm_havingvalue must follow the ServiceNow aggregate format:aggregate^field^operator^value(for example,COUNT^state^>^10).