How to make sysparm_query a variable using Get REST API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2021 09:31 AM
Hello,
Is possible to make sysparm_query a variable?
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2021 09:43 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
Reference Link

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 10:01 PM
Are you going to be executing this from within ServiceNow? If so, use variables in your HTTP Method.
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.
While the script sample uses hard coded examples, the values can be replaced with dynamically set variables.
https://youtube.com/watch?v=zYi8KhP9SUk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 10:07 PM
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
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader