Complex query with and and or conditions

jean-lucchatton
Kilo Guru

Hello,

I'im trying to create a complex query with and and or conditions.

What is working is a mix of and and or like that : (U OR V) AND (W OR Y OR Z).

What is need is a mix like this : (A AND B) OR C OR D OR E

My code :

var qc = current.addQuery('locationIN' + locations);

qc.addQuery('u_visible_by_external_provider', true);

var qr =   current.addOrCondition('assignment_group', IN', Usergroups);

qr.addOrCondition('caller_id', u);

qr.addOrCondition('opened_by', u);

But is don't work

I've also tried with and encode query but there is a know bug by ServiceNow (https://community.servicenow.com/message/963069#963069 and

ServiceNow KB: PRB647484: Using operator (^NQ) in encoded queries causes incorrect reference links i... ).

Could you help me please ?

Jean-Luc

8 REPLIES 8

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

What happens if you chain all your conditions?



current.addQuery('locationIN' + locations).


addQuery('u_visible_by_external_provider', true).


addOrCondition('assignment_group', IN', Usergroups).


addOrCondition('caller_id', u).


addOrCondition('opened_by', u);


It doesn't work


Anurag Tripathi
Mega Patron
Mega Patron

Hi Jean,



When i need to apply any such complex query i try to add filters, copy query from there and use it as EncodedQuery in my GlideRecord.



Now what you need here is a scenario like this


  • [Active] [is] [true] AND [Category] [is] [Hardware]
  • Top level OR condition
  • [Active] [is] [false] AND [Category] [is] [Software]


Here is a link that Explains how you can use the BIG AND and BIG OR to make these queries.


http://wiki.servicenow.com/index.php?title=Using_Filters_and_Breadcrumbs#Using_OR_Conditions



Hope this helps


-Anurag

Hi Anurag,



Thanks for your answer but I doesn't work. If you read carefully my original post you will see the reference to the documented ServiceNow bug



Jean-Luc