ServiceNow Encoded Query Translator

Live

Turn ^-separated encoded queries into plain English, catch the mistakes that match everything or nothing, edit them visually, and generate code and URLs.

Input

Encoded query, list URL or REST URL
Sets the field names, choice labels and checks, and the table in the code
Examples

Parsed 6 conditions · 1 sort · 1 tip

  • Tip“contains” cannot use a database index, so on a big table like incident it reads every row. If you can, use “starts with”, an exact value, or a keyword search (123TEXTQUERY321=…).

Plain English

Read for incident
whereActiveistrue
and
any of
Priorityis1 - Critical
Priorityis2 - High
andAssigned tois empty
andShort descriptioncontainsemail
andOpenedis after7 days ago
sortCreated (descending)

Builder

Edits rewrite the query above
where
and
or
andno value
and
and
sort

Output

for incident
background script · js
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^priority=1^ORpriority=2^assigned_toISEMPTY^short_descriptionLIKEemail^opened_atRELATIVEGT@day@ago@7^ORDERBYDESCsys_created_on');
gr.query();
while (gr.next()) {
    gs.info(gr.getValue('number') || gr.getUniqueValue());
}

Paste into System Definition › Scripts – Background on a sub-production instance to test.

What is an encoded query?

ServiceNow stores list filters as a compact string called an encoded query. Copy one from any list by right-clicking the filter breadcrumb and choosing Copy query. Scripts use the same format through GlideRecord.addEncodedQuery(), and REST calls through sysparm_query.

Pro tip: build the filter in the list view first, copy the query, and paste it into addEncodedQuery(). It's faster and less error-prone than chaining addQuery() calls.

Cheat sheet

^
AND
^OR
OR with the previous condition
^NQ
Start a new query; results are combined
ORDERBY / ORDERBYDESC
Sort ascending / descending
LIKE
Contains
STARTSWITH / ENDSWITH
Starts / ends with
IN / NOT IN
Is one of / is not one of
ISEMPTY / ISNOTEMPTY
Is empty / is not empty
^^
A literal ^ inside a value

How to translate a ServiceNow encoded query

  1. Paste the query. A raw encoded query, a sysparm_query value, a list URL or a full nav_to.do link all work.
  2. Pick the table. Field names and choice values such as State are read for that table, and it goes into the code and URLs.
  3. Read it in plain English. Each condition is shown as field, operator and value, grouped the way ServiceNow evaluates ^OR, ^NQ and related-list conditions.
  4. Fix what it finds. Typos in field names, conditions that can never match, names in reference fields and other mistakes are flagged, most with a one-click fix.
  5. Edit it visually. Change fields, operators, values, sorting and grouping without hand-editing carets.
  6. Copy what you need. GlideRecord, addQuery(), GlideAggregate or GlideQuery code, a list URL, a Table API URL or a shareable link back to this page.

ServiceNow encoded query operators

Every condition is written as field + OPERATOR + value, with no spaces between them. These are the operators you will meet in list filters, scripts and REST calls.

OperatorMeaningExample
=is (equals)priority=1
!=is notstate!=7
LIKEcontainsshort_descriptionLIKEvpn
NOT LIKEdoes not containshort_descriptionNOT LIKEtest
STARTSWITHstarts withnumberSTARTSWITHINC00
ENDSWITHends with[email protected]
INis one of (comma-separated)stateIN1,2,3
NOT INis not one ofcategoryNOT INhardware,network
ISEMPTYis emptyassigned_toISEMPTY
ISNOTEMPTYis not emptyassignment_groupISNOTEMPTY
ANYTHINGany value, including emptycmdb_ciANYTHING
EMPTYSTRINGis an empty stringcorrelation_idEMPTYSTRING
< <= > >=less / greater than (numbers and dates)reassignment_count>2
BETWEENis between two valuessys_created_onBETWEENjavascript:gs.dateGenerate('2026-01-01','00:00:00')@javascript:gs.dateGenerate('2026-01-31','23:59:59')
ON / NOTONis (not) on a date or periodsys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()
RELATIVEGT / RELATIVELTis after / before a relative timesys_updated_onRELATIVEGT@hour@ago@24
MORETHAN / LESSTHANmore / less than a time span from another date fieldresolved_atMORETHANopened_at@day@after@3
SAMEAS / NSAMEASsame as / different from another fieldopened_bySAMEAScaller_id
GT_FIELD / LT_FIELDgreater / less than another fieldsys_updated_onGT_FIELDsys_created_on
DYNAMICmatches a dynamic filter, such as Meassigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe
INSTANCEOFis a class or any of its child classessys_class_nameINSTANCEOFcmdb_ci_computer
VALCHANGES / CHANGESTOvalue changes (business rule and notification conditions)stateCHANGESTO6

Joining conditions: ^, ^OR, ^NQ and ORDERBY

^OR binds tighter than ^, so active=true^priority=1^ORpriority=2 reads as "active and (priority 1 or 2)". Use ^NQ when you need OR between whole groups.

SyntaxMeaningExample
^AND: both conditions must matchactive=true^priority=1
^OROR with the condition right before itpriority=1^ORpriority=2
^NQNew query: OR between whole groups of conditionspriority=1^NQassigned_toISEMPTY
ORDERBY / ORDERBYDESCSort ascending / descending by a fieldactive=true^ORDERBYDESCsys_created_on
GROUPBYGroup results (lists and reports)active=true^GROUPBYassignment_group
RLQUERY … ENDRLQUERYRecords with (or without) matching related recordsactive=true^RLQUERYtask_sla.task,>=1^has_breached=true^ENDRLQUERY
GOTOAdded by the search box above a list; filters like any other conditionGOTOnumber>=INC0010000
^EQEnd-of-query marker added by some lists; safe to ignoreactive=true^EQ
^^A literal ^ inside a valueshort_descriptionLIKEA^^B

Common ServiceNow encoded query examples

Copy-ready queries for everyday filters. Open any of them in the translator to read or adapt it.

Using an encoded query in GlideRecord, list URLs and the REST API

The same string works everywhere. In URLs, encode it first: = becomes %3D, ^ becomes %5E and , becomes %2C.

Server script: GlideRecord.addEncodedQuery()
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^priorityIN1,2^ORDERBYDESCsys_created_on');
gr.query();
while (gr.next()) {
  gs.info(gr.getValue('number') + ' ' + gr.getValue('short_description'));
}
List view URL
https://<instance>.service-now.com/incident_list.do?sysparm_query=active%3Dtrue%5EpriorityIN1%2C2%5EORDERBYDESCsys_created_on
REST Table API (GET)
https://<instance>.service-now.com/api/now/table/incident?sysparm_query=active%3Dtrue%5EpriorityIN1%2C2%5EORDERBYDESCsys_created_on&sysparm_limit=10

Frequently asked questions

What is an encoded query in ServiceNow?

An encoded query is the compact text form of a list filter, such as active=true^priority=1. Each condition is a field, an operator and a value, and conditions are joined with ^ (AND), ^OR and ^NQ. The same string works in list URLs (sysparm_query), in scripts through GlideRecord.addEncodedQuery(), and in the REST Table API.

How do I copy the encoded query from a list?

Filter the list, then right-click the last part of the filter breadcrumb and choose Copy query. You can also take the sysparm_query value from the list URL, or call gr.getEncodedQuery() in a script. Paste any of these into the translator above, including full nav_to.do links.

What is the difference between ^OR and ^NQ?

^OR joins one condition to the condition right before it, as in "priority is 1 or 2". ^NQ starts a completely new query, so the result is every record that matches the first group of conditions or the second group, as in "(active and P1) or (unassigned)".

How do I use an encoded query in a GlideRecord script?

Call gr.addEncodedQuery('active=true^priority=1') before gr.query(). Building the filter in the list view first and copying the query avoids typos in field names and operators. The translator also writes the equivalent addQuery() lines if you prefer them.

Why does my encoded query return every record?

By default ServiceNow ignores conditions on field names it does not recognise, so a typo such as prority=1 quietly matches everything. The same happens with spaces around the operator (priority = 1) or a capital letter in the field name. The translator flags these and offers the fix. You can also set the system property glide.invalid_query.returns_no_rows to true so that invalid queries return no rows instead.

Why does state=3 mean different things on different tables?

Choice values belong to each table. state=3 is On Hold on incident, Closed on change_request and Closed Complete on sc_task, and problem states start at 101. Pick the table in the translator to read the values with the right names; it also warns when a value is not one of the table's out-of-the-box choices.

What does RLQUERY mean in an encoded query?

RLQUERY is a related-list condition: it matches records by their related records. RLQUERYincident.problem_id,>=1^ENDRLQUERY finds problems with at least one incident. The first part is the related table and the field on it that points back, then comes the count (>=1 for at least one, =0 for none), and any conditions before ^ENDRLQUERY filter the related records. To add them from the list filter, turn on Allow related list query conditions to be added through the filter in the List v3 properties.

Why does "is Beth Anglin" not match on a reference field?

Reference fields such as Assigned to store the sys_id of the record they point to, so assigned_to=Beth Anglin matches nothing. Dot-walk to the name instead, assigned_to.name=Beth Anglin, or use the sys_id. The translator spots names in reference fields and rewrites the condition for you.

How do I count records per group from an encoded query?

Use GlideAggregate: addEncodedQuery() for the filter, addAggregate('COUNT'), and groupBy() for each field you group by. Add GROUPBYassignment_group to the query (or use + group by in the builder) and the GlideAggregate tab writes the script, one line per group.

How do I filter on "Me" or "One of my groups"?

Use dynamic filters: assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe means "assigned to me", and assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744 means "assignment group is one of my groups". A script value such as assigned_to=javascript:gs.getUserID() also works.

Does this tool connect to my ServiceNow instance?

No. The translator runs entirely in your browser and never asks for instance credentials. Nothing you paste is uploaded, so it is safe to use with queries from tickets, Slack messages or production lists.