- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2016 09:16 AM
Pretty basic question I think.. but I'm drawing a blank:
u_somefield=NULL^request_lineISNOTEMPTY^NQu_anotherfield=9697d9046f3a3100f24ced250d3ee40f
Encoded queries are not fun for maintenance, so I try to stick to "addQuery()" type functions.
The above query is really two queries, or a single query with a level of nesting.
u_somefield=NULL^request_lineISNOTEMPTY
+
u_anotherfield=9697d9046f3a3100f24ced250d3ee40f
How can I write this using standard addQuery/addNull.. etc with the appropriate nesting?
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2016 09:48 PM
This might be a bit simpler.
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
}
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2016 08:09 AM
Ahh, that's an interesting way to do it. Write two simple queries and extract the encoded query to combine them.
Benefit of the encoded query with the distinctive query elements of addQuery().
There are cases where that could be easier to maintain than a long encoded query..
Did you test this? Does addEncodedQuery always slap it on to the end of the existing resulting encodedQuery?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2016 04:53 PM
Yeah, I tested it out.
It appends it to the existing query.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2022 03:56 AM
Hi Stephen,
Fix for incorrect reference links while using (^NQ) operator : https://community.servicenow.com/community?id=view_idea&sysparm_idea_id=26aaaafddb4011d45205e6be1396...
Solution : Whenever we use ^NQ operator to join multiple queries to build a master query
we need enter ^current.getEncodedQuery() at every (^NQ) operator JOINs before moving to final encoded query
Example :
Levelcheck1 : hr_service.u_service_entity=3ef7cbc287e68d900d9f7447cebb359d
Levelcheck2 : hr_service.u_service_entity=0e974b8287e68d900d9f7447cebb35e2^assignment_group=fe7be44b8751b0100d9f7447cebb3515
Levelcheck3 : number=HRC0052382^ORnumber=HRC0001703
Mergedquery1 = Levelcheck1+^NQLevelcheck2+ "^" + current.getEncodedQuery();
Mergedquery2 = Mergedquery1+^NQLevelcheck2+ "^" + current.getEncodedQuery();
current.addEncodedQuery(Mergedquery2)
Regards,
Deepak R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2024 04:21 AM
Sharing what I have learned recently!
Be careful with ^NQ in your queries. When they are used SN does not use the Indexes of the table. Instead the system does table scans.
Striking right?!?! Read item number 6 here -> https://www.servicenow.com/community/developer-articles/performance-best-practice-for-efficient-quer...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2016 06:37 PM