Encoded Query Strings

From ServiceNow Wiki
Jump to: navigation, search
Navigation and User Interface
Related Topics
Note
Note: The latest release that this documentation applies to is Fuji. For documentation on the Geneva release, see Encoded query strings. Documentation for later releases is also on docs.servicenow.com.


1 Overview

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.

You can create encoded query strings manually or copy them from list filters.

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:

active=true

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:

category=network

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:

roles=itil

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:

install_status=1

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:

active=true^roles=itil

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:

roles=itil^ORroles=admin

To add multiple conditions where one condition is a JavaScript function, use this syntax: javascript:'field=value^' + function(). The function must return a string that can be concatenated with the first string to produce a valid query string. For example, to return all active users and meet the conditions of the getGroupQualifier() function, use:

javascript:'active=true^' + getGroupQualifier()

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:

unit_name=day^ORDERBYvalue

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
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

You can generate an encoded query string through a filter on any list and paste the string into a URL query or a reference qualifier.

  1. Open a list of records.
  2. Construct the filter.
  3. Click Run.
  4. Right-click the end of the filter breadcrumbs and select Copy query from the context menu.
    Selecting Copy query

  5. Use your computer's keyboard copy command to copy the query in the dialog box to your system clipboard.
    Copy the query to your computer's clipboard

  6. Click OK to close the dialog box.
  7. 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

Was this article helpful?
Yes, I found what I needed
No, I need more assistance