- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 03:57 AM
Hello- I have use rest call to get the count of records. I can see in REST API explorer that some of the parameters are available in SNOW rest call. But I want to pass the data of those parameter bases on user entry and pass dynamically to the rest call instead of hard coded.
Let me know how we can do that.
Suppose: I have created a REST Call called "Test Fuji" and It has end point define https://snow1.servicenow-com/api/now/stats/{tableName}
I want to use Get and pass the data of tableName dynamically through script and sysparm_query, count etc through query to get the data.
Please let me know how to do that.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 04:36 AM
It doesn't do the encoding automatically. You can do it using the ScopedGlideURI API call.
Scoped GlideURI API Reference - ServiceNow Wiki
Example (untested):
var q = 'active=true^priority=1';
var endpoint = https://myinstance.service-now.com/api/now/table/incident?sysparm_query=' + q;
var gURI = new ScopedGlideURI();
var uri = gURI.toString(endpoint); //returns fully encoded URI

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 04:00 AM
Hi,
In the REST API Explorer, there is a link (several of them actually) to provide you the JavaScript code to build your script.
Use that to see a code snippet to build the rest of your script. You can include the sysparm_query info in there.
Getting Started with REST - ServiceNow Wiki
REST API Explorer - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 04:08 AM
Hi Chuck- Thanks for quick response. Do I need to do use like "r.setStringParameter ('sysparm_query', "active=true")" to append the query in end point. Please correct me if I am wrong.
Also, do i need to define sysparmquery in "http parameters" also?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 04:11 AM
It goes on the endpoint. Here's a quick example I got from the code snippet by simply specifying incidents where the short description contains "SAP".
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev22335.service-now.com/api/now/table/incident?sysparm_query=short_descriptionLIKESAP&sysparm_limit=1');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 04:29 AM
Hi Chuck- I have seen that. My question is I have to pass the data of sysparm_query and sysparm_count dynamically from script include based on user entry. User query would be different based on the requirement.
As in rest call SNOW convert special character like "=" to "%3D" automatically so how I would like to know if pass active=true from script . Does SNOW automatically this to %3D in rest call?
Can you send me syntax to add query parameter through server side script and how to handle encoded query?
Sorry, I am new in this area so don't have much idea.
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev13251.service-now.com/api/now/stats/incident?sysparm_query=active%3Dtrue&sysparm_count=true');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());