ServiceNow Statistics

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.

service-now-statistics-overview.png

 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, or sysparm_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  

Known Issues

None.

Snap Views

View

Description

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, {"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 an original key.

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

Field Name

Field Type

Description

Label*
Default Value: ServiceNow Statistics
Example: Incident Count

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*
Default Value: N/A
Example: incident

String

The name of the ServiceNow table to query. Suggestions load from the connected instance. This field does not support expressions.

Query parameters
Default Value: N/A
Example:

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 sysparm_count). Reserved characters in values (=, ^, spaces) are URL-encoded automatically. Parameter names offer suggestions for common sysparm_* options. Parameter values support expressions and can be driven per input document.

Number of retries
Default Value: 5
Example: 3

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)
Default Value: 3
Example: 2

Integer

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

Snap Execution

Default Value:  Validate & Execute
Example: Validate & Execute

Dropdown list

Select one of the following three modes in which the Snap executes:

  • Validate & Execute: Performs limited execution of the Snap based on Preview Document Count value in User settings 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.

Examples

Example 1: Simple Count

Configuration:

Parameter Name

Parameter Value

Parameter Name

Parameter Value

sysparm_count

true

Table name: incident

Output:

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

Example 2: Multiple Aggregations

Configuration:

Parameter Name

Parameter Value

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

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, or sysparm_max_fields) is required. Sending 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).