- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2016 05:33 PM
I had to build a content page that lists incidents with a particular set of filters in an iframe, and was doing so via building it in the URL contained in the iframe.
I've gotten it to where I wanted it to be, but I don't really understand why it functions the way it does. My issue came about because I needed to figure a way to group a set of AND statements against other OR statements. Something like the following:
(Caller is (insert js function here))
OR
(Opened by is (insert js function here))
OR
(Company is not empty
AND Company name is not (insert company name here))
The only way I was able to accomplish this in URL query parameters was by in the sysparm_query value replacing those ^OR instead with ^NQ. I only came up with this by building the query out in an incident filter and copying the URL it spat back.
Looking at: http://wiki.servicenow.com/index.php?title=Operators_Available_for_Filters_and_Queries#gsc.tab=0
I don't really see why this works the way it does. ^NQ should just be the same as != by my understanding, which isn't at all what I'm going for here, but I can assure you the query works as I intended it, with ^NQ essentially functioning as a grouped OR. Has anyone ever run into this, or does anyone know what I might be missing here?
Best regards,
Brian
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2016 05:58 PM
Hi Brian, (nice name, btw)
I believe (^NQ) indicates a "new query", which like you said operates like a grouped-OR... looking for a match in either the query conditions preceding it OR the ones that follow. And I'm pretty sure you could get away with just replacing the second "OR" in your query logic:
i.e.,
(Caller is (insert js function here)) ^OR (Opened by is (insert js function here)) ^NQ (Company is not empty ^ Company name is not (insert company name here))
Obviously, I've just put in the important parts for demonstration. Please don't use this at home. I've seen the documentation you mentioned which relegates '^NQ' to be essentially the same as '!='... and I agree that's more than a little confusing. Take a look here for some better explanation:
Hopefully that explanation helps a little bit.
Thanks,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2016 05:40 PM
This might help you understand why all three are needed and what they do differently.
As far as I know, you need to use addEncodedQuery() to query with a grouped OR. I have given an example in the link below.
Re: How to combine two queries into one result set without encoded query.
active=true^short_descriptionLIKEbla^ORshort_descriptionLIKEhello^NQactive=false^short_descriptionLIKEkit
^ = AND
^OR = OR
^NQ = OR
Hope this makes sense
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
04-05-2016 05:58 PM
Hi Brian, (nice name, btw)
I believe (^NQ) indicates a "new query", which like you said operates like a grouped-OR... looking for a match in either the query conditions preceding it OR the ones that follow. And I'm pretty sure you could get away with just replacing the second "OR" in your query logic:
i.e.,
(Caller is (insert js function here)) ^OR (Opened by is (insert js function here)) ^NQ (Company is not empty ^ Company name is not (insert company name here))
Obviously, I've just put in the important parts for demonstration. Please don't use this at home. I've seen the documentation you mentioned which relegates '^NQ' to be essentially the same as '!='... and I agree that's more than a little confusing. Take a look here for some better explanation:
Hopefully that explanation helps a little bit.
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2016 09:10 AM
Thank you very much to both of you, I have a more solid understanding now of why ^NQ is essentially signifying a new query, and not a !=
Best regards,
Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 03:52 AM
Hi Brian,
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