addOrCondition() not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 11:11 AM
When I tried to execute the code below, in a Background script, in our Test instance, it only returned a row count of 1.
Both of the POs being queried exist.
When I swap the values in the addQuery() and addOrCondition() functions, whichever 'gr.number' value is in the 'addQuery()' function is the one that is found.
var gr = new GlideRecord('proc_po');
gr.addQuery('number','PO000273');
gr.addOrCondition('number','PO002225');
gr.query();
gr.next();
gs.print(gr.getRowCount() + ':' + gr.number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 12:56 PM
I believe you have to assign one of your queries to a variable and then add the next or condition or you can just dot-walk out to the next query condition. Then if you want to iterate through all that is found you would need to loop through it such as using a while loop or something. These two examples should work:
Example one:
var count = 1;
var gr = new GlideRecord('proc_po');
var qry = gr.addQuery('number','PO000273');
qry.addOrCondition('number','PO0002225');
gr.query();
gs.print( 'Records found: ' + gr.getRowCount());
while(gr.next()){
gs.print( count + ':' + gr.number);
count++;
}
Example two:
var count = 1:
var gr = new GlideRecord('proc_po');
gr.addQuery('number', 'PO000273').addOrCondition('number', 'PO0002225');
gr.query();
gs.print( 'Records found: ' + gr.getRowCount());
while(gr.next()){
gs.print( count + ':' + gr.number);
count++;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2014 05:52 AM
Thanks Chris, that works great!
I also found some of examples of this here...
http://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2014 06:19 AM
Hi,
I can see some issue in code.Refer the below link to know the syntax for addorcondition,