How to make sysparm_query a variable using Get REST API?

Inged
Kilo Contributor

Hello,

Is possible to make sysparm_query a variable?

find_real_file.png

Instead of This

request.setEndpoint('https://<instance>.service-now.com/api/now/table/live_group_member?sysparm_query=group.name%3DSystem%2C%20User&sysparm_display_value=true&sysparm_limit=10');

Be like this in the business rule:

var group = current.group.name;
request.setEndpoint('https://<instance>.service-now.com/api/now/table/live_group_member/{group}');

Thanks.
3 REPLIES 3

Pranav Bhagat
Kilo Sage

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

 

Reference Link

 

https://community.servicenow.com/community?id=community_question&sys_id=9e54c369dbd8dbc01dcaf3231f96...

John VanBruggen
Giga Guru

Are you going to be executing this from within ServiceNow?  If so, use variables in your HTTP Method.

find_real_file.png

In this example I have 3 variables in the URL.  If you preveiw the script usage the first portion of the script shows you how to set those variables.

find_real_file.png

While the script sample uses hard coded examples, the values can be replaced with dynamically set variables.

Check out my Consultant's Survival Guide
https://youtube.com/watch?v=zYi8KhP9SUk

Ankur Bawiskar
Tera Patron
Tera Patron

@Inged 

You can use variable substitutions for this

https://<instance>.service-now.com/api/now/table/live_group_member?sysparm_query=${myQuery}&sysparm_display_value=true&sysparm_limit=10');

Variable substitution in outbound REST messages

then use -> setStringParameterNoEscape

Scripting REST Messages

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader