- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 10:03 AM
Hi there,
I have a script include within a scoped application. I need to iterate through the records of a table and and populate an array with a specific attribute.
i.e.
var records= [];
var gr = new GlideRecord("u_group_records");
gr.addQuery('date1', '>=', start).addCondition('date2', '<=', end);
gr.query();
while(gr.next()){
records.push(gr.name.getDisplayValue());
}
However I need to test multiple OR conditions and would have expected the following to work:
var records= [];
var gr = new GlideRecord("u_group_records");
gr.addQuery('date1', '>=', start).addCondition('date2', '<=', end)
.addOrCondition('date1', '<', start).addCondition('date2', '>', end)
.addOrCondition('date1', '<', start).addCondition('date2', '<', end).addCondition('date2', '>', start);
gr.query();
while(gr.next()){
records.push(gr.name.getDisplayValue());
}
All this does is test the first conditions and then ignore the rest.
If I create multiple queries with an individual condition in each, I'm able to get the desired result, however this seems inefficient...
Any advice much appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 11:09 AM
I believe Sanjiv means to do something like this:
var eq = 'date1>=' + start + '^date2<=' + end;
gr.addEncodedQuery(eq);
Although this would work too: gr.addEncodedQuery('date1>=' + start + '^date2<=' + end);
You have to include variables outside of the quotes and concatenate them where needed with the '+'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 10:16 AM
You may want to go into your custom table and define your search criteria there. Then you can copy the query and use it in an encoded query string:
Generate an encoded query string through a filter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 10:45 AM
Thanks, but already tried that. date1, start, date2 and end are variables and the encoded query didn't seem to like them...
i.e.
gr.addQuery('date1', '>=', start).addCondition('date2', '<=', end); looks like:
gr.addEncodedQuery('date1>=start^date2<=end');
No joy...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 10:49 AM
The encoded query is fine. Build the complete query and copy it. It replaces and with ^ and or with OR.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 10:54 AM
Hi there, thanks, but this is the encoded query and it doesn't work: gr.addEncodedQuery('date1>=start^date2<=end');