- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2017 12:03 PM
I added 2017-01-18 in the U.S. Holidays schedule entry list,when i run below code...schedin.isInSchedule(datevalidation) return false value.
please help me to resolve below issue.
var schedRec = new GlideRecord('cmn_schedule');
schedRec.addQuery('name', 'U.S. Holidays');
schedRec.query();
if (schedRec.next()) {
var schedin = new GlideSchedule(schedRec.sys_id);
var datevalidation = new GlideDateTime();
datevalidation.setDisplayValue("2017-01-18 06:10:13");
if (schedin.isInSchedule(datevalidation))
{
gs.log("Is in the schedule");
}
else
{
gs.log("Is NOT in the schedule");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2017 12:50 PM
Date/times can be tricky and the isInSchedule() function can accept a second parameter for a time zone. If one is not entered then it defaults to the system time zone. Since you are using setDisplayValue you are likely wanting the user's timezone to be used and then it is comparing it to system, thus not working. So to solve this you need to get your timezones in sync.
You could set datevalidation to gs.nowDateTime(), UTC time or you could pass in a timezone in the isInSchedule() function like:
if (schedin.isInSchedule(datevalidation, "US/Eastern"))
See this other community post for another example:
isInSchedule() giving unexpected results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2017 12:50 PM
Date/times can be tricky and the isInSchedule() function can accept a second parameter for a time zone. If one is not entered then it defaults to the system time zone. Since you are using setDisplayValue you are likely wanting the user's timezone to be used and then it is comparing it to system, thus not working. So to solve this you need to get your timezones in sync.
You could set datevalidation to gs.nowDateTime(), UTC time or you could pass in a timezone in the isInSchedule() function like:
if (schedin.isInSchedule(datevalidation, "US/Eastern"))
See this other community post for another example:
isInSchedule() giving unexpected results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2017 01:35 PM
thanks for reply.
i tried as you suggested,,,with parameter ,
if (schedin.isInSchedule(datevalidation, "US/Eastern")) and i set the my instance Time zone to US/Eastern.but same result. returning false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2017 09:00 PM
Hi,
when i set Holiday schedule entry type as none..then issue is resolved got true value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 04:15 AM
Hi AnilKumar,
I am stuck in the same situation wherein the program would always return 'False'. What did you mean when you said - 'when i set Holiday schedule entry type as none..then issue is resolved got true value.'
This could help me.
Thanks.
Sharad