GlideRecord addorcondition with muliple conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 07:14 AM
Can I add and andorcondition that includes more than one query ?
For example I want to do the following:
The only thing common between all 3 queries is the name = department, but I cant use it in the OR condition from the addQuery piece. I understand they are completely separate. Any advice? It would be easier not to use an encoded query as I have to slice up and join together strings etc. Thanks
var grd = new GlideRecord('cmn_department');
grd.addQuery('parent.name', location_first);
grd.addQuery('name', '=', department);
grd.addorcondition('parent.name', location_second) AND ('name', '=', department);
grd.addorcondition(''parent.name', location_third) AND ('name' '=', department);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 07:17 AM
Hi,
With each subsequent addQuery you are applying AND condition.
addOrCondition should be used then for each AND condition use addQuery again.
Thanks
Sudhanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 07:23 AM
Would you be able to show mewith an example? That would help. Im not sure of the syntax to do an addquery after the addorcondition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 07:31 AM
Like this:
var gr=new GlideRecord("table_name");
gr.addOrCondition("parent.name",location_second);
gr.addOrCondition("parent.name",location_third);
gr.addQuery('parent.name', location_first);
gr.addQuery('name', '=', department);
gr.query();
Thanks
Sudhanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 08:11 AM
Have you tried this one?
var gr =new GlideRecord('incident');
var qc = gr.addQuery('parent.name', location_first);
gr.addOrCondition("parent.name",location_second);
gr.addOrCondition("parent.name",location_third);
gr.addQuery('name', '=', department);
gr.query();
gs.info(gr.getRowCount());