Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to query data using GlideHTTPRequest?

Ravish Shetty
Tera Guru

Hello,

With GlideHTTPRequest, i can delete, update and insert data.

However there is this one use case where i want to fetch some data by querying it. In the documentation i did not find anything for that.

Here is the code what i use today using john andersens RESTMessageScripted. I want to use GlideHTTPRequest instead of RESTMessageScripted.


var r = new RESTMessageScripted("post", "https://"+instanceName+".service-now.com/sys_user_grmember.do");

r.addHeader("Content-Type", "application/json");

r.addRequestParameter("JSONv2", "true");

r.addRequestParameter("sysparm_query", 'group='+group+'^user='+user);

r.setBasicAuth(authenticatingUsername, authenticatingPassword);

response = r.execute();

var jsonData = new JSON().decode(response.getBody().toString());

if(jsonData.records.length == 0){

return true;

} else {

return false;

}

Edit: As shown in Line 4 of the script, i am applying a specific query. I want to do the same with GlideHTTPRequest so that i do not fetch all the data. Can i apply a specific query using GlideHTTPRequest?

1 ACCEPTED SOLUTION

Better yet, use %5E instead of ^ and it will work.



You can also use request.addParameter('sysparm_query', 'active=true%5Enumber=xxxxxxx') to set the query.


View solution in original post

16 REPLIES 16

I don't know the sys id of the data in the first place. Example: If i want to see if a user record is present in a target environment, i just have the email id of the user id with me...so naturally i will apply a query like sysparm_query=email=XYZ.


Hi ravio,



Does my last reply fix the issue you are having?



Better yet, use %5E instead of ^ and it will work.



You can also use request.addParameter('sysparm_query', 'active=true%5Enumber=xxxxxxx) to set the query.