
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 01:40 PM
I have this script on a Catalog task Due date field. It's supposed to set the due date of the task to 5pm ET 3 days after an event date. Our instance is set to ET, and the schedule and child schedule is set to ET.
When I run the script, the logs show 5pm on the due date, but when it actually sets the value of the due date field on the task, it sets it to 1pm.
var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;
var endDateTime = new GlideDateTime(endDate);
gs.log('EndDateTime: ' + endDateTime,"KC"); //Returns 2024-08-30 00:00:00
endDateTime.addSeconds(61200); //Set date to 5pm on date of event (17hrs*60mins*60secs)
gs.log('EndDateTime: ' + endDateTime,"KC"); //Returns 2024-08-30 17:00:00
var dur = new GlideDuration('0 27:00:00'); //3 days = 27 hours on an 8-5 schedule
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var dueDate = sched.add(endDateTime,dur);
gs.log('DueDate: ' + dueDate,"KC"); //Returns 2024-08-30 17:00:00
return dueDate;
Seems like it's seeing the due date as the UTC time, and then setting it to ET in the task. How do I fix this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:56 PM
Try like this:
var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;
// Initialize the GlideDateTime with the event date
var endDateTime = new GlideDateTime();
endDateTime.setDisplayValue(endDate + ' 17:00:00'); // Set to 5 PM ET
gs.log('Event DateTime (5 PM ET): ' + endDateTime.getDisplayValue());
// Define the schedule (8-5 weekdays excluding holidays)
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
// Add 3 business days to the event date
var dueDate = sched.add(endDateTime, new GlideDuration('3 00:00:00'));
// The resulting due date should also be at 5 PM ET on that date.
dueDate.setDisplayValue(dueDate.getDisplayValue().split(' ')[0] + ' 17:00:00');
gs.log('Due DateTime after adding 3 business days: ' + dueDate.getDisplayValue());
// Check the UTC time of the due date
gs.log('Due DateTime in UTC: ' + dueDate.getValue());
// Output the due date in ET (should already be in the correct time zone)
gs.log('Final DueDate in ET: ' + dueDate.getDisplayValue());
If you're still having issues, double-check the time zone on the schedule itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 03:36 PM
In the context of which user does your script run? What time zone is set in that user's profile?
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:56 PM
Try like this:
var endDate = fd_data._20__for_each.item.date_s_and_time_s_of_the_event;
// Initialize the GlideDateTime with the event date
var endDateTime = new GlideDateTime();
endDateTime.setDisplayValue(endDate + ' 17:00:00'); // Set to 5 PM ET
gs.log('Event DateTime (5 PM ET): ' + endDateTime.getDisplayValue());
// Define the schedule (8-5 weekdays excluding holidays)
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
// Add 3 business days to the event date
var dueDate = sched.add(endDateTime, new GlideDuration('3 00:00:00'));
// The resulting due date should also be at 5 PM ET on that date.
dueDate.setDisplayValue(dueDate.getDisplayValue().split(' ')[0] + ' 17:00:00');
gs.log('Due DateTime after adding 3 business days: ' + dueDate.getDisplayValue());
// Check the UTC time of the due date
gs.log('Due DateTime in UTC: ' + dueDate.getValue());
// Output the due date in ET (should already be in the correct time zone)
gs.log('Final DueDate in ET: ' + dueDate.getDisplayValue());
If you're still having issues, double-check the time zone on the schedule itself.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 04:53 AM
Thank you!!! This worked like magic! The only exception is that I had to change the GlideDuration from '3 00:00:00' to '0 27:00:00'. Otherwise it added 8 days ((3 days*24 hours)/9 business hours) instead of 3.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 05:23 AM - edited 08-14-2024 05:24 AM
Be careful with parsing date/time display values. GlideDateTime objects' getDisplayValue() method returns the date and time in the current user's display format and time zone. It can have a different value and syntax depending on which user's context the script will run in.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/