- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 06:46 AM
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.
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()){
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 07:12 AM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 06:49 AM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 07:03 AM
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()){

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 07:12 AM
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!