I want to add a query using gr.addEncodedQuery to the existing query. How can I get the existing encoded query into a var?

scott111
Kilo Expert

I want to add a query using gr.addEncodedQuery to the existing query. How can I get the existing encoded query into a var?

1 ACCEPTED SOLUTION

var encodedQuery = gr.getEncodedQuery();

But that's not necessary to add an encoded query to an existing query.

View solution in original post

5 REPLIES 5

Manik
ServiceNow Employee
ServiceNow Employee

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.

 

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!

var encodedQuery = gr.getEncodedQuery();

But that's not necessary to add an encoded query to an existing query.

scott111
Kilo Expert

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?