Encoded Query Strings
| Note: This article applies to Fuji and earlier releases. For more current information, see Encoding Query Strings at http://docs.servicenow.com
The ServiceNow Wiki is no longer being updated. Visit http://docs.servicenow.com for the latest product documentation.
An encoded query string represents a complex filter on a list of records. Use encoded query strings to include a filter as part of a URL parameter, such as the sysparm_query URL parameter, or as a reference qualifier to restrict the data that is selectable for a reference field.
2 Creating Encoded Query Strings
The following examples illustrate how you can create encoded string queries. For a complete list of operators available for queries, see Operators Available for Filters and Queries.
2.1 Referring to Boolean or String Values
To create a query string on Boolean fields, use this syntax: field=true or field=false. For example, to return only active records in a table, use:
To create a query string with a field that has a specific string value, use this syntax: field=value. For example, to return incident records where the category is network, use:
2.2 Referring to Reference Fields
To create a query string that refers to a reference field in another table, use this syntax: field_in_referenced_table=value. For example, to return users with the itil role in the Assigned to reference field on the Incident form, use:
2.3 Referring to Choice List Values
To create a query string that refers to a choice list option, use the value of the choice list, not the label, with this syntax: choice list field=value. For example, to return configuration items (CIs) with the status Installed, which has a value of 1 in the choice list, use:
See Determining Values Associated with Choices for Scripting to find the options for the values.
2.4 Using Multiple Conditions
To use two conditions joined together by an AND operator, use the carat ^ symbol in this syntax: field1=value1^field2=value2. For example, to return all active users with the "itil" role, use:
To use two conditions joined together by an OR operator, use the carat symbol with OR with this syntax: field1=value1^ORfield1=value2. For example, to return all users with either the "itil" or "admin" roles, use:
2.5 Listing Values in Order
To sort data by a specific field, use the ORDERBY condition with the following syntax: field1=value^ORDERBYfield2.
For example, to return the days of the week in order from the Day of the Week [sys_cal_unit] table, use:
In the Day of the Week table, unit_name is the field that specifies day, week, or month, and value is a numerical value for each day from 1 (Monday) to 7 (Sunday). The query string returns a list of the days of the week in order from the lowest value, which represents Monday, to the largest value, which represents Sunday.
|Note: Reference qualifiers do not support the ORDERBY condition. In reference qualifiers, you can sort the reference lookup list by using standard list controls. To specify the order of an autocomplete list for a reference field, use the ref_ac_order_by dictionary attribute.|
3 Generating Encoded Query Strings through a Filter
- Open a list of records.
- Construct the filter.
- Click Run.
- Right-click the end of the filter breadcrumbs and select Copy query from the context menu.
- Use your computer's keyboard copy command to copy the query in the dialog box to your system clipboard.
- Click OK to close the dialog box.
- Use the query string to construct a URL or an advanced reference qualifier.
3.1 Using the CONTAINS Operator
When you use the CONTAINS operator on a list filter, the system translates the filter to a LIKE query. For example, if you filter for active records with numbers that contain 123, the URL is https://InstanceName.service-now.com/incident_list.do?sysparm_query=active%3Dtrue%5EGOTOnumberLIKE123