Check if date falls under schedule for specific timezone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 05:24 AM
Hi Community,
I need help with the code to check if date falls under schedule for specific timezone.
I am using isInSchedule() method, for some reason its not giving correct output, I have used this several times in past not sure why its giving me hard time now, may be i am missing some small point.
Tried various approaches:-
1.Basic approach to use getDisplayValue to get user's session timezone.
2. Another approach is to convert time zone and then give in isInSchedule method, for this i tried setTZ() and setTimeZone() both method, both are converting properly and getting output as per timezone only however schedule function is still not returning correct output.
Please let me know what i am missing here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 06:54 AM
then based on that field select the schedule and pass that sysId and check if the date falls in schedule
what's the challenge?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 07:03 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 08:02 PM
Hi Ankur, I understand its a simple check, not sure if i am missing something here.
My approach is to convert start date based on the required timezone and then compare it with the respective schedule(in schedule also timezone is given). for that i tried below ways, i am able to convert date in timezone properly however it seems like isInSchedule is validating in UTC timezone and thats why returning false.
1. Timezone converstion via setTimeZone
var gr = new GlideRecord("change_request");
gr.get("sys_id");
var planStartDate= gr.start_date;
var timeZone ="IST";
var startDate = new GlideDateTime(planStartDate);
gs.print(startDate); //UTC Date
startDate.setTimeZone(timeZone);
var startDateInTz = startDate.getDisplayValue(); //string value
var newStartDate= new GlideDateTime(startDateInTz); //convert to object
gs.print("newStartDate "+newStartDate); //getting date as per timezone
var sch= new GlideSchedule("sys_id"); using IST schedule
gs.print(sch.isInSchedule(newStartDate)); //schedule is 20:30 -5:30am IST but on checking i realized its giving true when newStartDate is between 15:00 - 0:00 so basically -5:30 (UTC time).
2. Timezone converstion via setTz - Here also same timezone conversion is working properly but schedule is not giving proper output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 09:02 PM
but in your schedule what's the timezone?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 07:27 AM
Hi Ankur,
I created two schedules, in one US timezone is given and in 2nd one IST.
I need to validate if start date is in business hours as per the given schedule.
Based on condition i need to validate start date with either US schedule or IST one.
Regards,
Muskan Dixit