DSL Reference
SN-Viz uses a pipe-delimited, key=value query language to describe what data to fetch and how to visualize it. Each query is a single line of clauses separated by |.
Only table= is required. All other parameters are optional and have sensible defaults. Clauses can be written in any order.
Query Anatomy
Each clause has the form key=value. Whitespace around | and = is ignored. Keys are case-insensitive.
All Parameters
| Parameter | Values | Default | Description |
|---|---|---|---|
| table= | any SN table name | — | ServiceNow table to query (e.g. incident, change_request) |
| filter= Optional | SN encoded query string | none (all records) | ServiceNow filter string using standard operators. Supports ^ (AND) and ^OR (OR). |
| stat= Optional | COUNT | AVG(field) | SUM(field) | MIN(field) | MAX(field) | COUNT | Aggregate function. For AVG/SUM/MIN/MAX, the field name is required inside parentheses. |
| by= Optional | field name (dot-walk supported) | none | Primary group-by field. Supports comma-separated multiple fields (deprecated — use by2= for 2D). Maps to the X-axis on bar charts. |
| by2= Optional | field name | none | Second group-by field creating a 2D matrix. Maps to the series/legend (colors) on bar charts, and Y-axis on heatmaps. |
| trend= Optional | field BY day|week|month|quarter|year | none | Time-series grouping on a date field. Produces a line or area chart automatically. |
| bucket= Optional | field [range1, range2, ...] | none | Groups records into numeric ranges. Each bucket produces one bar. See Bucket Ranges section below. |
| viz= Optional | bar|pie|donut|line|area|heatmap|scatter|treemap|gauge|number|table|auto | auto | Explicit chart type. With auto, SN-Viz picks the best type based on your data shape. |
| sort= Optional | asc | desc | desc | Sort direction for grouped results. Sorts by the stat value. |
| limit= Optional | positive integer | none (all) | Max number of groups to display from the primary grouping (by=). Groups are sorted by total value before slicing. |
| limit2= Optional | positive integer | none (all) | Max number of groups from the secondary grouping (by2=). Only applicable when by2= is set. |
| target= Optional | numeric value | none | Draws a red dashed horizontal target/threshold line on bar, line, and area charts. |
| having= Optional | AGG^FIELD^OP^VALUE | none | Post-aggregation filter (like SQL HAVING). Filters groups after stats are computed. |
| label= Optional | any text | none | Sets the panel title. Overwrites the editable panel heading when the query is executed. |
| drilldown= Optional | true | false | true | Enable or disable click-to-drilldown navigation. When enabled, clicking a data point opens a filtered ServiceNow list. |
| from= Optional | date string (YYYY-MM-DD or relative) | none | Start of the date window. Applies a filter on datefield. |
| to= Optional | date string | none | End of the date window. Used with from=. |
| datefield= Optional | any date field name | sys_created_on | Which date field to apply from=/to= filters on. Also used as the default field for trend queries. |
filter=
Accepts a ServiceNow encoded query string — the same format used in SN list views. Use ^ for AND, ^OR for OR, and standard SN field operators.
| = | Equals |
| != | Not equals |
| CONTAINS | Contains (LIKE) |
| STARTSWITH | Starts with |
| ISEMPTY / ISNOTEMPTY | Is/Is not empty |
| IN | In list (comma-separated values) |
| != | Not equals |
| > / < / >= / <= | Numeric or date comparison |
stat=
Defines the aggregate function applied to each group. Default is COUNT.
| Value | Description | Requires field |
|---|---|---|
| COUNT | Count of records in each group | No |
| AVG(field) | Average value of field across each group | Yes |
| SUM(field) | Sum of field values across each group | Yes |
| MIN(field) | Minimum field value in each group | Yes |
| MAX(field) | Maximum field value in each group | Yes |
by= and by2=
by= is the primary group-by field. It maps to the X-axis on bar charts, and to the primary dimension on heatmaps and scatter plots.
by2= is the secondary group-by field. It creates a 2D matrix, mapping to the legend/color series on bar charts, and to the Y-axis on heatmaps.
trend=
Groups results by a date field over time into equal-width buckets. Produces a line or area chart. Add by= to split into multiple series — one line per group value.
Syntax: trend=<date_field> BY <interval>
| Interval | Description |
|---|---|
| day | One bucket per calendar day |
| week | One bucket per week (Mon–Sun) |
| month | One bucket per calendar month |
| quarter | One bucket per fiscal quarter |
| year | One bucket per year |
bucket=
Groups numeric field values into custom ranges. Each range becomes one bar. Cannot be combined with by= or trend=.
Syntax: bucket=<field> [range1, range2, ...]
viz=
Selects the chart type. When set to auto (default), SN-Viz picks the best type based on your data shape.
limit= and limit2=
limit= controls the maximum number of groups shown from the primary dimension (by=). limit2= controls the secondary dimension (by2=).
Groups are ranked by total value descending before slicing — so you always see the top N by volume.
target=
Adds a red dashed horizontal line to bar, line, and area charts at the specified numeric value. Useful for SLA thresholds or KPI goals.
having=
Filters groups after aggregation — equivalent to SQL's HAVING clause. Format: AGGREGATE^FIELD^OPERATOR^VALUE
| AGGREGATE | The stat: count, avg, sum, etc. |
| FIELD | The groupby field name (e.g. category) |
| OPERATOR | >, <, =, !=, >=, <= |
| VALUE | Numeric threshold value |
label=
Sets the panel title text when the query is executed. Overwrites the default "New Panel" heading. Useful when building dashboard layouts that need clear titles.
drilldown=
Controls whether clicking a chart element navigates to a filtered ServiceNow list. Default is true. Set to false to disable.
When enabled, clicking a bar, pie slice, scatter dot, or other element appends the clicked group value as a filter to the base query and opens the matching list view in ServiceNow.
from= / to= / datefield=
These three parameters define a date window filter applied on top of the query. Typically set via the panel's Date Window dialog rather than typed manually.
| Parameter | Description |
|---|---|
| from= | Start date. Accepts YYYY-MM-DD or ServiceNow relative date formats. |
| to= | End date. Used with from=. |
| datefield= | Date field to filter on. Defaults to sys_created_on. Also used as the default for trend queries. |
Dot-walking Fields
Any field in by=, by2=, stat=(field), bucket=(field), and filter= can traverse reference fields using dot notation. As you type, autocomplete suggestions follow the chain and show fields on the referenced table.
2D Charts with by= and by2=
When both by= and by2= are set, SN-Viz builds a 2D matrix from the two fields:
- Bar chart: by= → X-axis labels, by2= → stacked color series (legend)
- Heatmap: by= → X-axis, by2= → Y-axis rows
- Scatter: by= → X-axis, by2= → legend groups
Query Gallery
Copy any of these to get started immediately. All use the incident table which is universally present in ServiceNow instances.