Need to check if date is in schedul;e
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2014 06:04 AM
Hi,
i wrote a script to check if yesterdays date is in schedule of holiday or not but the script is returning false even if yesterdays date is a holiday,
pasting the script for reference please help me correct the code.
var now = new Date();
var yesterday = new GlideDateTime(gs.beginningOfYesterday());
var sched = new GlideSchedule('55ebbbf15f002000b12e3572f2b47714'); this is OOB schedule for US holidays (and yesterday is holiday as labor day)
var inSched = sched.isInSchedule(yesterday);
gs.log("answer schedule"+inSched);
- Labels:
-
Ask the Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2016 01:51 AM
Hi Vijay,
The US Holiday schedule is made up of schedule spans of type "Exclude". That is why it does not find the date in the schedule, if the type of a span is anything else, it is considered to be an include and will be factored when checking if the date is in the schedule.
You can test this by setting the schedule span for December 25th to anything other than "Exclude".
var date = new GlideDateTime("2016-12-25 00:00:00");
var schedule = new GlideSchedule("55ebbbf15f002000b12e3572f2b47714");
gs.print(date);
gs.print(schedule.isInSchedule(date));
Hope that helps,
Arya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2016 02:31 AM
Hi Vijay,
See if this works for you.
var curr_date = gs.nowDateTime();
gs.log("current date is " + curr_date);
var yesterday= new GlideDate();
yesterday.setValue(curr_date);
yesterday.addDays(-1);
gs.log("yesterday's date is " + yesterday);
var sched = new GlideSchedule('55ebbbf15f002000b12e3572f2b47714');
var inSched = sched.isInSchedule(yesterday);
gs.log("answer schedule"+inSched);
Please let us know if did not work.
Thanks,
Arnab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2016 02:41 AM
Hi Arnab,
The US Holiday schedule has spans of type exclude, which is why isInSchedule does not find the date in the schedule.
This is not the case of the incorrect date being passed.
Thanks,
Arya