- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 10:02 AM
Hi Lindsey,
Create a new schedule that runs 9am to 5pm every week day, then use the script below to calculate the due date.
Note, you'll need to set the myScheduleName, dueDays and dueWorkingHours.
// Get the datetime now
var nowGdt = new GlideDateTime();
// The name of the schedule
var myScheduleName = 'myScheduleName';
// The basis of our calculation
var dueDays = 3;
var dueWorkingHours = 8;
// The amount of time we want for the duration
var dueSeconds = dueDays*dueWorkingHours*60*60;
var leadTime = new GlideDuration(leadTimeSeconds*1000);
// Calculate the Due Date!
var dueDateGdt;
var schedRec = new GlideRecord('cmn_schedule');
if (schedRec.get('name', myScheduleName)) {
var sched = new GlideSchedule(schedRec.sys_id);
dueDateGdt = sched.add(nowGdt, leadTime, '');
}
gs.log('The Due Date is: '+dueDateGdt.getDisplayValue()); // Hurrah!
Andy