Calculate Due Date based on Time Zone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 02:02 PM
We have employee terminations that need to happen at certain times of the day based on time zone. If an employee is being terminated on 9/1 in the US/Eastern that employee termination should fire at 5:00pm at the end of 9/1. This works fine for that time zone. Now issue becomes if a Hong Kong employee is terminated then the end of day is 5:00pm in their time zone which in the EST time zone would be 5:00AM as there is a 12 hour time difference. I have tried several scripts and here is my current one and I cannot seem to get the due date to reflect when orchestration should begin:
gs.include('DurationCalculator');
executeSample();
function executeSample() {
// First we need a DurationCalculator object.
var dc = new DurationCalculator();
// -------------- Add a schedule to the date calculator ---------------------
addSchedule(dc);
//dc.setTimeZone("GMT+8")
dc.setStartDateTime("8/31/2017 00:00:00");
if (!dc.calcDuration(9*3600)) { // 2 days
gs.log("*** Error calculating duration");
return;
}
gs.log(dc.getEndDateTime());
}
function addSchedule(durationCalculator) {
// Load the "8-6 weekdays" schedule into our duration calculator.
var scheduleName = "8-6 weekdays";
var grSched = new GlideRecord('cmn_schedule');
grSched.addQuery('name', scheduleName);
grSched.query();
if (!grSched.next()) {
gs.log('*** Could not find schedule "' + scheduleName + '"');
return;
}
durationCalculator.setSchedule(grSched.getUniqueValue(), "GMT");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 02:13 PM
I figured out my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 11:16 AM
What was the solution to this? Could you provide the details?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 11:23 AM
I need to account for Daylight Savings time so I added a line in the code to determine if the date selected was using Daylight savings time. I also added schedules at the locations and had the script look at the location of the terminated user to determine which timezone to use.
Final Script:
gs.include('DurationCalculator');
executeSample();
function executeSample() {
// First we need a DurationCalculator object.
var dc = new DurationCalculator();
// Load a schedule.
addSchedule(dc);
// Compute a duration using the schedule.
var termDate = new GlideDateTime(current.variables.effective_date); //initialize startTime
var isDST = termDate.isDST();
gs.log('Termination Date is ' + termDate + "Daylight savings is " + isDST);
//dc.setTimeZone("GMT+7");
dc.setStartDateTime(termDate);
if (!isDST){
if (!dc.calcDuration(10*3600)) { // 2 days
gs.log("*** Error calculating duration");
return;
}
}
else {
if (!dc.calcDuration(9*3600)) { // 2 days
gs.log("*** Error calculating duration");
return;
}
}
//gs.log(dc.getEndDateTime());
current.due_date = dc.getEndDateTime();
}
function addSchedule(durationCalculator) {
// Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.
var scheduleName = current.variables.location.u_schedule.name;
gs.log('Location schedule is ' + scheduleName);
var grSched = new GlideRecord('cmn_schedule');
grSched.addQuery('name', scheduleName);
grSched.query();
if (!grSched.next()) {
gs.log('*** Could not find schedule "' + scheduleName + '"');
return;
}
durationCalculator.setSchedule(grSched.getUniqueValue(), "GMT");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 04:07 AM
Hi @aritha,
I have the same requirement to trigger the flow Designer at Termination dateTime in user's local timezone. Can you please help me understand the script which you have posted, where you have written this and the inputs that are required for this script.
I will try to create an action and pass the inputs and output the duration on how much time the flow should wait