- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 09:26 AM
I want to add a query using gr.addEncodedQuery to the existing query. How can I get the existing encoded query into a var?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 10:04 AM
var encodedQuery = gr.getEncodedQuery();
But that's not necessary to add an encoded query to an existing query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 09:53 AM
Hi Scott,
What is the reason for trying to get existing encoded query in a var? It is possible to have more that one encoded query as part of same GlideRecord query.
Eg:
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=false');
gr.addEncodedQuery('state=1^assignment_group=c468fa1088b6914071a26a5b6365a8c6');
gr.query();
Hope this helps. In case it doesn't , please elaborate your problem a bit so that i can further help you on it.
Thanks,
Manik
PS - Please mark correct and helpful, like if solves your issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 09:58 AM
Take a look at this as it's basically taking a query from one... and running it again with another query:
var gr = new GlideRecord('table');
gr.addQuery('u_somefield', NULL);
gr.addQuery('request_line', '!=', NULL);
var queryTwo = new GlideRecord('table');
queryTwo.addQuery('u_anotherfield', '9697d9046f3a3100f24ced250d3ee40f');
gr.addEncodedQuery("^NQ" + queryTwo.getEncodedQuery());
gr.query();
while(gr.next()){
//Process
}
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
‎04-10-2018 10:04 AM
var encodedQuery = gr.getEncodedQuery();
But that's not necessary to add an encoded query to an existing query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 10:59 AM
I need to do this as part of a solution for this requirement: Users must not be able to access any incident assigned to a security group unless they are a member of that security group, one of its parent groups or they are the caller.
I am writing code in a business rule that lists the hierarchy of security groups then creates an encoded query like this (assume Security is the parent group and the others are child groups): https://blahtest.service-now.com/incident_list.do?sysparm_query=active%3Dtrue%5Ecaller_id%3De70zzcba6f81x200e0abd15eae3eez3d%5Eassignment_group%3Dec5x0x866f2e3100x8ad31012e3eez2a%5EORassignment_group%3D1270d3bb6f0c6200xxe6ceb2be3eez22%5EORassignment_group%3Dfec053bb6f0c6200xxe6ceb2be3eez07%5EORassignment_group%3D7820x3bb6f0c6200xxe6ceb2be3eezz1%5ENQactive%3Dtrue%5Eassignment_group!%3Dec5x0x866f2e3100x8ad31012e3eez2a%5Eassignment_group!%3D1270d3bb6f0c6200xxe6ceb2be3eez22%5Eassignment_group!%3Dfec053bb6f0c6200xxe6ceb2be3eez07%5Eassignment_group!%3D7820x3bb6f0c6200xxe6ceb2be3eezz1 (sys_ids obfuscated).
If you were to create a list view with the above encoded query it would look like the attached pic. Assume that active=true is the existing query. You can see I would need to duplicate it in the second part of the query (see bolded text).
Better way?