The purpose of this guide is to walk you through several examples of how to query for data using the Search ServiceNow Records activity.
You can enter a query such as "name-value pairs=state=closed" which says to filter the list of objects (such as an Incident) where the state is closed. This is described on ServiceNow's documentation and you can test this out using the ServiceNow REST API explorer. Our activity takes the query that the user supplies and appends it to the relevant ServiceNow REST API call and then receives the results.
The problem for some customers is that it is not easy to understand how to create queries, how to test queries, or that the person is not technical to the extent that learning and using the ServiceNow REST API explorer is practical.
ServiceNow's documentation regarding building queries that can be used with their REST API is located in the Encoded query strings documentation. This is a useful resource if you want to learn how to build queries that can be used with the Search ServiceNow Records Activity.
Below are some query examples that can be used with the Incidents object:
Returns all records, but returns only the three columns specified (number, sys_created_on, and sys_created_by)
Return all records where state is closed
Return only the three columns (number, sys_created_on, and sys_created_by) for each record, return only records where the state is Open, and limit the results to 1 record.
Return all records where the priority is 2
Return all records where the short description is like network
Return one record where the number is INC0010060 and only return three columns as part of the result (sys_id, number, short_description)
There are two other methods to create and obtain useful queries that can be used with this activity.
- Option A: Copy any query from the ServiceNow UI.
- Option B: Copying the querystring from the browser.
You will need to prepend the text "sysparm_query=" to any query that results per the steps below.
Go to an object, Incidents in this case.
Clear out the filters and create a new filter. In our case we are looking for any Incidents whose number ends with the string "100"
Copy the query suing the Copy Query menu item. It will look like numberENDSWITH100.
Paste this into the Search ServiceNow Records activity. You can do this in the Test Query window as seen below, or in the query property of the activity.
Be sure to pre-pend sysparm_query= in front so that it looks like sysparm_query=numberENDSWITH100, else it will not work correctly.
In this option you do not have to remember to do add anything as a pre-pending step. You can copy and paste the query string if you use the Open new Window option like below:
Create the filter you want to use as before in Option A
Step3: Copy the query string in toto (everything after the question mark "?"). Then paste it directly in the “Test Query” dialog of the Search ServiceNow Records activity as seen below.
Updated about a month ago