Help to add an OR condition to a GlideRecord query

shane_davis
Tera Expert

I have the top 3 conditions working in the script code below, but want to add the OR condition to it.  I thought about the addOrQuery but I am thinking this will add the "OR" under the 4th set rather than as it's own query.  The conditions are separated by line vs being one encoded query because I have heard that the one encoded query may have issues.

The OR condition is "Status IS ONE OF In Stock and Retired"....you just can't see Retired on the screenshot.

find_real_file.png

 

var ci= new GlideRecord("cmdb_ci");
ci.addEncodedQuery('last_discoveredONLast 7 days@javascript:gs.beginningOfLast7Days()@javascript:gs.endOfLast7Days()');
ci.addQuery('serial_number', '!=', '');
ci.addQuery('serial_number', 'DOES NOT CONTAIN', 'XXXXXXXXXX');
ci.query();
while(ci.next()){
1 ACCEPTED SOLUTION

Yep, that looks great!  There's nothing about a 'per-line' structure that works any better (other than maybe code readability).

Please mark the response above as correct if I've answered your question.  Thanks!

View solution in original post

3 REPLIES 3

Mark Stanger
Giga Sage

The simplest way of doing this is just to navigate directly to that table and construct your query using the standard list condition builder.  Then you can right-click the breadcrumb and select 'Copy query' to grab an entire encoded query string that you could use in your 'addEncodedQuery' line.

Mark,

     Thank you for the quick reply.  I had copied the query previously, but due to being told that queries per line worked better than the encoded query in some cases, I didn't use it.  If I follow what you're saying, the code below will be my final result.  Am I correct on what you mean?  I appreciate your help.

var ci= new GlideRecord("cmdb_ci");
ci.addEncodedQuery('last_discoveredONLast 7 days@javascript:gs.beginningOfLast7Days()@javascript:gs.endOfLast7Days()^serial_numberISNOTEMPTY^serial_numberNOT LIKEXXXXXXX^NQinstall_statusIN6,7');
ci.query();
while(ci.next()){

 

      

Yep, that looks great!  There's nothing about a 'per-line' structure that works any better (other than maybe code readability).

Please mark the response above as correct if I've answered your question.  Thanks!