Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Glide Record OR and AND

poyntzj
Kilo Sage

I am looking up on the cmb_schedule_span table

I have the schedule so I am only looking at the records for that schedule, but I need to lookup based on the repeat_type and the days_of_week fields.

 

repeat_type is daily or weekMWF or weekdays

OR

repeat_type is weekly AND days_of_week contains 1

In other words, if the schedule affects a Monday.

 

I have

var seRT = scheduleEntry('repeat_type','daily');
seRT.addOrCondition('repeat_type','weekMWF');
seRT.addOrCondition('repeat_type','weekdays');
seRT.addOrCondition('repeat_type','weekly');

 

which brings me back a record

I cannot see anyway to add restrict it any further

I have looked at encoded queries and they are not quite getting there either

It decides to use the ^NQ option to create a new query which throws the results.

 

schedule=ca51a84c6fcd61407e874c871e3ee4ad^repeat_type=daily^ORrepeat_type=weekMWF^ORrepeat_type=weekdays^NQrepeat_type=weekly^days_of_weekLIKE1

 

I am at the moment thinking of using the first query and then looking at a quick scan in the data it returns, but would prefer to do this in a single query is possible

 

any ideas or pointers.

1 ACCEPTED SOLUTION

Huh, that's strange.



I'm using the following in my instance, and it picks up the expected records for Daily, MWF, Weekdays, and weekly on Mondays.   I have other records where the repeat_type is weekly and it excludes those.



var scheduleEntry = new GlideRecord('cmb_schedule_span');  


//Initial criteria to add all repeat_type values of interest
scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays,weekly');        


//Criteria to exclude the repeat_type of "weekly" unless for the specific day of interest
var seRT = scheduleEntry.addQuery('repeat_type','!=','weekly');
seRT.addOrCondition('days_of_week','CONTAINS','1');  
scheduleEntry.query();  
gs.print(scheduleEntry.getRowCount());



The code you have in your post is not quite the same.   Can you try the following & verify if the record is excluded?


var scheduleEntry = new GlideRecord('cmb_schedule_span');


//querying for record that should be excluded due to other criteria


scheduleEntry.addQuery('schedule','ca51a84c6fcd61407e874c871e3ee4ad');  


//Initial criteria to add all repeat_type values of interest
scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays,weekly');        


//Criteria to exclude the repeat_type of "weekly" unless for the specific day of interest
var seRT = scheduleEntry.addQuery('repeat_type','!=','weekly');
seRT.addOrCondition('days_of_week','CONTAINS','1');  
scheduleEntry.query();  


if(scheduleEntry.next()){


gs.log(scheduleEntry.name);


}


 

View solution in original post

6 REPLIES 6

Huh, that's strange.



I'm using the following in my instance, and it picks up the expected records for Daily, MWF, Weekdays, and weekly on Mondays.   I have other records where the repeat_type is weekly and it excludes those.



var scheduleEntry = new GlideRecord('cmb_schedule_span');  


//Initial criteria to add all repeat_type values of interest
scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays,weekly');        


//Criteria to exclude the repeat_type of "weekly" unless for the specific day of interest
var seRT = scheduleEntry.addQuery('repeat_type','!=','weekly');
seRT.addOrCondition('days_of_week','CONTAINS','1');  
scheduleEntry.query();  
gs.print(scheduleEntry.getRowCount());



The code you have in your post is not quite the same.   Can you try the following & verify if the record is excluded?


var scheduleEntry = new GlideRecord('cmb_schedule_span');


//querying for record that should be excluded due to other criteria


scheduleEntry.addQuery('schedule','ca51a84c6fcd61407e874c871e3ee4ad');  


//Initial criteria to add all repeat_type values of interest
scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays,weekly');        


//Criteria to exclude the repeat_type of "weekly" unless for the specific day of interest
var seRT = scheduleEntry.addQuery('repeat_type','!=','weekly');
seRT.addOrCondition('days_of_week','CONTAINS','1');  
scheduleEntry.query();  


if(scheduleEntry.next()){


gs.log(scheduleEntry.name);


}


 

Yup that worked a treat