how to add OR between two IF statements

Alon Grod
Tera Expert

How can I add OR Between these two AND conditions:

 

var oa = new GlideRecord('u_operational_activity');
oa.addQuery('u_departments',dept);
oa.addQuery('u_impact_services', service);
oa.addQuery('u_from_date','<=',date_created);
oa.addQuery('u_to_date','>=',date_created);
OR
oa.addQuery('u_departments','');
oa.addQuery('u_impact_services', service);
oa.addQuery('u_from_date','<=',date_created);
oa.addQuery('u_to_date','>=',date_created);
oa.query();
if(oa.next()){
return true;
}

1 ACCEPTED SOLUTION

Ajay30
Mega Guru

Hello, I don't think there is any inbuilt method to write an OR condition between two AND's. However you can use filter condition and copy the query and then put that query in addQuery(). But here I can see some dynamic variable which we cannot put in the filter.

One solution from my side:

 

var oa = new GlideRecord('u_operational_activity');
oa.addQuery('u_departments',dept);
oa.addQuery('u_impact_services', service);
oa.addQuery('u_from_date','<=',date_created);
oa.addQuery('u_to_date','>=',date_created);

 

if(oa.next()){
return true;
}
else{

var oa1 = new GlideRecord('u_operational_activity');
oa1.addQuery('u_departments','');
oa1.addQuery('u_impact_services', service);
oa1.addQuery('u_from_date','<=',date_created);
oa1.addQuery('u_to_date','>=',date_created);
oa1.query();
if(oa1.next()){
return true;
}

return false;

}


 

View solution in original post

4 REPLIES 4

Ajay30
Mega Guru

Hello, I don't think there is any inbuilt method to write an OR condition between two AND's. However you can use filter condition and copy the query and then put that query in addQuery(). But here I can see some dynamic variable which we cannot put in the filter.

One solution from my side:

 

var oa = new GlideRecord('u_operational_activity');
oa.addQuery('u_departments',dept);
oa.addQuery('u_impact_services', service);
oa.addQuery('u_from_date','<=',date_created);
oa.addQuery('u_to_date','>=',date_created);

 

if(oa.next()){
return true;
}
else{

var oa1 = new GlideRecord('u_operational_activity');
oa1.addQuery('u_departments','');
oa1.addQuery('u_impact_services', service);
oa1.addQuery('u_from_date','<=',date_created);
oa1.addQuery('u_to_date','>=',date_created);
oa1.query();
if(oa1.next()){
return true;
}

return false;

}


 

@Alon Grod @Ajay30 

Gliding and querying same table multiple time is not recommended.

you can achieve it with single glide record using addQuery or addEncodedQuery.

 

Thanks,

Bharath

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Rahul RJ
Giga Sage
Giga Sage

@Alon Grod  You can try encoded query simply you have to go to list view and add the condition same condition you can use here.

 You can try the below code.

 

var oa = new GlideRecord('u_operational_activity');
oa.addEncodedQuery(oa.addEncodedQuery("u_departments="+dept+"^u_impact_services="+service+"^u_from_date<="+date_created+"^u_to_date>="+date_created+"^NQu_departmentsISEMPTY^u_impact_services="+service
+"^u_from_date<="+date_created+"^u_to_date>="+date_created);
oa.query();
if(oa.next()){
return true;
}

 

or simply by adding or condition department you can achieve same

Regards,

RJ

 

BharathChintala
Mega Sage

@Alon Grod 

var oa = new GlideRecord('u_operational_activity');
oa.addQuery('u_departments',dept).addOrCondition('u_departments','');
oa.addQuery('u_impact_services', service);
oa.addQuery('u_from_date','<=',date_created);
oa.addQuery('u_to_date','>=',date_created);

if(oa.next()){
return true;
}

 

Try this

 

Thanks

Bharath

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala