GlideRecord addorcondition with muliple conditions

anfield
Tera Guru

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);

8 REPLIES 8

Sudhanshu Talw1
Tera Guru

Hi,

With each subsequent addQuery you are applying AND condition.

addOrCondition should be used then for each AND condition  use addQuery again.

 

Thanks

Sudhanshu

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

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

 

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());