- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 04:24 AM
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;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 04:45 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 04:45 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 05:55 AM
Gliding and querying same table multiple time is not recommended.
you can achieve it with single glide record using addQuery or addEncodedQuery.
Thanks,
Bharath
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 04:58 AM - edited 01-17-2023 05:01 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 04:58 AM
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
Bharath Chintala