ServiceNow Statistics

Overview

The ServiceNow Statistics Snap computes aggregate statistics—count, sum, average, minimum, and maximum—over a ServiceNow table using the Stats API (/api/now/stats/{table_name}), without fetching individual records.


The Settings tab of the ServiceNow Statistics Snap, showing the Label, Table name, Query parameters, Number of retries, Retry interval (seconds), and Snap execution fields.

Supported Accounts

Prerequisites

  • A valid ServiceNow account configured in SnapLogic.
  • The ServiceNow instance must support the Aggregate (Stats) API, which requires the Paris release or later.
  • At least one aggregate parameter must be provided in Query parameters: sysparm_count, sysparm_avg_fields, sysparm_sum_fields, sysparm_min_fields, or sysparm_max_fields. ServiceNow rejects a request without at least one of these parameters with a 400 error.

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, or sysparm_max_fields) is required. A request without one results in a 400 error from ServiceNow.
  • The sysparm_having value must follow the ServiceNow aggregate format aggregate^field^operator^value, for example COUNT^state^>^10.

Snap views

Type Description Examples of upstream and downstream Snaps
Input

This Snap has at most one document input view.

When an input document is present, expression-enabled fields in Query parameters can reference values from the upstream document.

Output

This Snap has exactly one document output view and produces one document per input document containing the Stats API result as-is.

  • For ungrouped queries, the output contains a single stats object, for example {"stats": {"count": "42"}}.
  • For grouped queries, the output contains a result field holding an array of group entries.

When an input document is present, the original input is included under the original key.

Error

Common errors include an invalid table name (404), a missing aggregate parameter (400), an authentication failure (401), and insufficient permissions (403). The error document includes the ServiceNow error text in the reason field.

Learn more about Error handling.

Snap settings

Note: Learn about the common controls in the Snap settings dialog.
Field/Field set Description

Label

String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: ServiceNow Statistics

Example: Incident Count

Table name*

String/Suggestion

Specify the name of the ServiceNow table to query. Suggestions load from the connected instance.

Note: Only accounts that have the Personalize dictionary role can see the field labels associated with each table in the ServiceNow data dictionary. Therefore, accounts used with Snaps in this Snap Pack must have the Personalize dictionary permission if you want to view the Table name suggestions.

Default value: None.

Example: incident

Query parameters

A key-value table of query parameters to send to the Stats API. Add one row per parameter. Rows with a blank Parameter name are skipped. A blank Parameter value is still sent, which supports presence-only options such as sysparm_count.

Parameter name

String/Suggestion

Specify the name of the query parameter. Suggestions list the common sysparm_* options.

Default value: None.

Example: sysparm_avg_fields

Parameter value

String/Expression

Specify the value of the query parameter. This field supports expressions, so the value can be driven per input document. Reserved characters in values (=, ^, and spaces) are URL-encoded automatically.

Default value: None.

Example: reassignment_count

Number of retries

Integer/Expression

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.

Default value: 5

Example: 3

Retry interval (seconds)

Integer/Expression

Specify the number of seconds the Snap waits between each retry attempt.

Default value: 3

Example: 2

Snap execution

Dropdown list
Choose one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute: Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only: Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Default value: Validate & Execute

Example: Validate & Execute

Examples

Count the records in a table

Set Table name to incident and configure Query parameters as follows:

Parameter name Parameter value
sysparm_count true

The Snap writes the following output document:

{
  "stats": {
    "count": "42"
  }
}

Compute multiple aggregations in one request

Set Table name to incident and configure Query parameters as follows:

Parameter name Parameter value
sysparm_count true
sysparm_avg_fields reassignment_count
sysparm_sum_fields reassignment_count
sysparm_min_fields reassignment_count
sysparm_max_fields reassignment_count

The Snap writes the following output document:

{
  "stats": {
    "count": "42",
    "avg": {"reassignment_count": "2.35"},
    "sum": {"reassignment_count": "99"},
    "min": {"reassignment_count": "0"},
    "max": {"reassignment_count": "8"}
  }
}