- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 10:05 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 12:41 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 10:47 AM
Hi Julian,
Can you try this pls:
var scheduleEntry = new GlideRecord('cmb_schedule_span');
var seRT = scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays');
seRT.addOrCondition('repeat_type','weekly');
seRT.addOrCondition('days_of_week','CONTAINS','1');
seRT.query();
if(seRT.next()){
//do something
}
Thanks & Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 11:04 AM
Hari's post is close. The following should work:
var scheduleEntry = new GlideRecord('cmn_schedule_span');
scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays,weekly');
var seRT = scheduleEntry.addQuery('repeat_type','!=','weekly');
seRT.addOrCondition('days_of_week','1');
scheduleEntry.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 12:10 PM
Afraid neither quite work
The schedule is Mon to Fri only
var scheduleEntry = new GlideRecord('cmn_schedule_span'); |
scheduleEntry.addQuery('schedule','ca51a84c6fcd61407e874c871e3ee4ad');
var seRT = scheduleEntry.addQuery('repeat_type','IN','daily,weekMWF,weekdays'); | ||
seRT.addOrCondition('repeat_type','weekly'); | ||
seRT.addQuery('days_of_week','CONTAINS','6'); | ||
scheduleEntry.query(); | ||
if(scheduleEntry.next()){ | ||
gs.log(scheduleEntry.name); | ||
} |
This returns the name even though with 6 or 7 it should return nothing.
I SQL I wojuld write
Select from table
where
(((repeat_type = 'daily' or repeat_type='weeklyWMF' or repeat_type='weekdays') OR (repeat_type='weekly' AND days_of_week Like 1)) AND schedule = sys_id)
Pity the encoded query tries to use ^NQ.
Cheers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 12:32 PM
Hi Julian,
How abt this encoded query?
repeat_type=weekMWF^ORrepeat_type=daily^ORrepeat_type=weekdays^schedule=ca51a84c6fcd61407e874c871e3ee4ad^NQrepeat_type=weekly^days_of_weekLIKE1
only difference with the one you used earlier is "ad^" after schedule sys id.
Also, i'm not sure if days_of_weekLIKE1 can be used here
Thanks,
Mandar