- 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 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 11:18 AM
Ah that makes sense now. Many thanks for your help!