Data retrieval API

Query for data by issuing an HTTPS GET request to the instance.

By default, a GET request is interpreted as a get function if a sysparm_sys_id parameter is present. Otherwise, it is interpreted as a getRecords function. You can also specify a URL parameter sysparm_action=get. Query responses are always encapsulated by a records hash of records, where each individual record's values are themselves hashed by field name.

Return Display Value for Reference Variables

When you are getting a record from a get or getRecords'/tt> function, all the fields associated with that record are returned. The fields are often reference fields that contain a sys_id for another table. The base system behavior is to return the sys_id value for those fields. To have the display value for the field returned, use one of these options:
  • Add the property <tt>glide.json.return_displayValue to the system properties, and every JSON request will return a display value for a reference field.
  • Add the parameter displayvalue=true to the JSON request URL and JSON requests with that parameter will return a display value instead of the sys_id for a reference field. The JSON URL would look like this:
    https://<instance name>.service-now.com/incident.do?JSON&sysparm_action=getRecords&sysparm_query=active=true^category=hardware&displayvalue=true
    
  • Add the parameter displayvalue=all to the JSON request URL and JSON requests with that parameter return a display value and the sys_id for a reference field. The response element name for the display value field will be prefixed with dv_, for example dv_caller_id.

Return Display Variables

Use the display variables parameter to return an array of variables associated with a service catalog item record when using a get or getRecords function. The variables are expressed hierarchically. A variable container has the container's variables in its children field.

To get display variables, add the parameter displayvariables=true to the JSON request URL. The JSON request URL would look like:
https://<instance name>.service-now.com/sc_req_item.do?JSONv2&sysparm_action=getRecords&
sysparm_query=active=true^short_description=Laptop%20preconfigured%20for%20developers&displayvariables=true
White space has been added to the following example for clarity:
"variables" : [ { "children" : null , "name" : "asset_tag" , "order" : 1300 , "question_text" : "Asset Tag" , "type" : 6 , "value" : "" } , { "children" : [ { "children" : null , "name" : "ste1" , "order" :- 1 , "question_text" : "Test" , "type" : 6 , "value" : "test" } ] , "name" : "Test one" , "order" :- 1 , "question_text" : "Testing" , "type" : 0 , "value" : null } , { "children" : null , "name" : "" , "order" : 200 , "question_text" : "Please specify an operating system" , "type" : 3 , "value" : "Windows XP" } , { "children" : [ { "children" : null , "name" : "create_item" , "order" : 1000 , "question_text" : "Create an Inventory Item?" , "type" : 7 , "value" : "" } ] , "name" : null , "order" :- 1 , "question_text" : "Options" , "type" : 0 , "value" : null } , { "children" : null , "name" : "serial_number" , "order" : 1100 , "question_text" : "Serial Number" , "type" : 6 , "value" : "" } , { "children" : null , "name" : "hard_drive" , "order" : 100 , "question_text" : "What size hard drive do you want?" , "type" : 3 , "value" : "60 GB" } , { "children" : null , "name" : "name" , "order" : 1200 , "question_text" : "Name of new inventory item" , "type" : 6 , "value" : "" } , { "children" : null , "name" : "company" , "order" : 1400 , "question_text" : "Manufacturer" , "type" : 8 , "value" : "" } ]

Control the order of records

You can control the order that records appear in the JSON response. To set an order, use the ORDERBY or ORDERBYDESC clauses in the URL encoded query. For example,

sysparm_query=active=true^ORDERBYnumber^ORDERBYDESCcategory

filters all active records and orders the results in ascending order by number first, and then in descending order by category. For more information, see Encoded query strings.

getKeys

Get the sys_id of multiple records by specifying an encoded query string in the sysparm_query parameter.
https://<instance name>.service-now.com/incident.do?JSONv2&sysparm_action=getKeys&sysparm_query=active=true^category=hardware

get

Get a record directly by specifying the sys_id in a sysparm_sys_id parameter.
https://<instance name>.service-now.com/incident.do?JSONv2&sysparm_sys_id=9d385017c611228701d22104cc95c371
Optionally, you may also specify the sysparm_action parameter:
https://<instance name>.service-now.com/incident.do?JSONv2&sysparm_action=get&sysparm_sys_id=9d385017c611228701d22104cc95c371

getRecords

Get all records by specifying an encoded query string in the sysparm_query parameter.
https://<instance name>.service-now.com/incident.do?JSONv2&sysparm_action=getRecords&sysparm_query=active=true^category=hardware