- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2020 05:46 PM
Hello,
How do I add Encoded multiple AND query in URL?
Following is Encoded Query.
"companyLIKEindia^model_category!=6d593627db9d4b44386879531f9619c0^model_category!=cd49b227db9d4b44386879531f9619e9"
var url = https://xxxx.service-now.com/api/now/table/alm_hardware?sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_limit=20000 &sysparm_fields=sys_id%2Cassigned_to";
Please advise.
Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2020 06:28 PM
Hello,
That error appears to be related to some other part of your code, not what I'm answering in this post.
You can comment out the url components and see if the error still occurs, if so, then it's related to something else.
I'm merely covering a url that is assigned to a variable as string and concatenating the sysparm_query piece on to it.
I know when I copied your script before...you had a space in your url...and it appears you didn't copy and paste what I posted...so maybe that's an issue.
var url = https://xxxx.service-now.com/api/now/table/alm_hardware?sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_limit=20000 &sysparm_fields=sys_id%2Cassigned_to";
Please review the script I posted...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2020 05:52 PM
Hi,
You should be able to easily append that to your URL like so (EXAMPLE😞
var encQuery = "companyLIKEindia^model_category!=6d593627db9d4b44386879531f9619c0^model_category!=cd49b227db9d4b44386879531f9619e9";
var url = "https://xxxx.service-now.com/api/now/table/alm_hardware?sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_limit=20000&sysparm_fields=sys_id%2Cassigned_to";
url += '&sysparm_query=' + encQuery;
And now you can use url as you need to.
Basically, using sysparm_query= and then your encodedquery string.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2020 06:09 PM
hi Allen,
Something is not working for me. Getting an error as below.
var encQuery = "companyLIKEindia^model_category!=6d593627db9d4b44386879531f9619c0^model_category!=cd49b227db9d4b44386879531f9619e9";
var url = "https://xxxx.service-now.com/api/now/table/alm_hardware?sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_limit=20000 &sysparm_fields=sys_id%2Cassigned_to";
url = url +'&sysparm_query=' + encQuery;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2020 06:28 PM
Hello,
That error appears to be related to some other part of your code, not what I'm answering in this post.
You can comment out the url components and see if the error still occurs, if so, then it's related to something else.
I'm merely covering a url that is assigned to a variable as string and concatenating the sysparm_query piece on to it.
I know when I copied your script before...you had a space in your url...and it appears you didn't copy and paste what I posted...so maybe that's an issue.
var url = https://xxxx.service-now.com/api/now/table/alm_hardware?sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_limit=20000 &sysparm_fields=sys_id%2Cassigned_to";
Please review the script I posted...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2020 07:41 PM
hi Allen,
If I comment out this highlighted code it returns the value.
but if I uncomment then it doesn't bring any result and thus null error exception, so I believe something still needs to be done on encoded query. (Some formatting I guess)
var encQuery = "companyLIKEindia^model_category!=6d593627db9d4b44386879531f9619c0^model_category!=cd49b227db9d4b44386879531f9619e9";
var url = "https://xxxx.service-now.com/api/now/table/alm_hardware?sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=sys_id%2Casset_tag%2Clocation%2Cassigned_to&sysparm_limit=30000";
//url = url +'&sysparm_query=' + encQuery;
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(url);
request.setHttpMethod('GET');
request.setRequestHeader("content-type","application/json");
request.setRequestHeader("cache-control", "no-cache");
request.setRequestHeader("Authorization", "Basic xxxxx");
request.setMIDServer("FTLDSNOWMID01");
var response = request.execute();
gs.info("Response Body:"+response.getBody());
var jsData= JSON.parse(response.getBody()); // convert json object into javascript object
gs.info("Total Records :"+ jsData.result.length);