How to compare if current time falls within a time period,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:50 AM
Hello community,
How can I script to check if current time falls within 9am and 5pm for example. The GDT uses the whole date time object, i'm only interested in time portion.
My use case is to route tickets based on ticket created time using assignment rule script. If created time is within 9am and 5pm, route to a specific team other to a default group.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Were you able to get answer to this. If yes please past here in community as well.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago - last edited a week ago
hi @Baba Femi
Please tried this script:
(function() {
var gdt = new GlideDateTime(current.sys_created_on);
//CRITICAL: Set the Timezone to the team's location
// If you don't do this, it defaults to GMT/UTC or System time
// Example: 'US/Pacific', 'Europe/London', 'Asia/Kolkata'
var timeZone = 'US/Eastern';
gdt.setTZ(Packages.java.util.TimeZone.getTimeZone(timeZone));
var hour = gdt.getLocalTime().getHourOfDayLocalTime();
//Logic: 9am (9) to 5pm (17)
if (hour >= 9 && hour < 17) {
current.assignment_group.setDisplayValue('Day Shift Team');
} else {
current.assignment_group.setDisplayValue('Night Shift Team');
}
})();
Happy to help! If this resolved your issue, kindly mark it as the correct answer and Helpful and close the thread so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
