- 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
‎01-28-2016 09:22 AM
gr.addQuery('u_somefield','');
gr.addQuery('request_line','!=','');
etc..
All these are "and" and if you want "or" use addOrCondition.
Hope this clears it up..
/Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2016 05:40 PM
Nope.. that's just a basic query.
I'm looking for nested queries like in my original example, note the bold text in the example.
"NQ" is very different from "^OR"
Thanks
-Stephen

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2016 05:49 PM
Hi Stephen,
Please refer the below link. Just copy the query from the filter and pass it as addQuery.
http://wiki.servicenow.com/index.php?title=Encoded_Query_Strings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2024 04:22 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...