
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 09:27 AM
I trying to set the due date based on the schedule and duration from the SLA on the RITM. I'm doing via a script because we have a log of generic workflow that just create 1 task and there are several different SLAs. Also just like the SLA is setup to start only after the RITM has been approved. The problem I am facing is that it is not following the schedule fully. My schedule is Monday - Friday from 8 - 5. I have an SLA setup is a 9 hour duration or 1 business day. When my script run it is setting the end time at 7 am the next day but 7 am is not in the schedule. Is there something I'm doing wrong. Here is my script include I'm passing the sys_id of the SLA that is on that catalog item.
var setDueDate = Class.create();
setDueDate.prototype = {
initialize: function() {},
CalculateDueDate: function(SLA) {
var gr = new GlideRecord('contract_sla');
var dur = "";
gr.addQuery('sys_id', SLA);
gr.query();
if (gr.next()) {
var temp = gr.duration.getDisplayValue().toString().split(' ');
if (temp.indexOf('Days') > -1 || temp.indexOf('Day') > -1){
dur = temp[0] + " " + temp[2] + ":00:00";
}
else {
dur = temp[0] + ":00:00";
}
var startDate = new GlideDateTime(gs.notDateTime());
var fullDur = new GlideDuration(dur);
var schedule = new GlideSchedule(gr.schedule, 'US/Pacific');
var end = schedule.add(startDate, fullDur);
return end;
}
},
type: 'setDueDate'
};
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2024 06:23 AM
Ok so I ran this as a background script using one of our SLA's that is three days 8 to 5 except weekends and as long as I left out the time zone when setting up the schedule var it works correctly. So I think you need to do the fix above and then remove the time zone. Once you set the due date it will automatically get displayed in the users time zone and I think thats whats throwing it off. There are two time zone offsets being included in the code you started with.
var setDueDate = Class.create();
setDueDate.prototype = {
initialize: function() {},
type: 'setDueDate'
};
setDueDate.CalculateDueDate = function(SLA) {
var gr = new GlideRecord('contract_sla');
if (gr.get(SLA)) {
var startDate = new GlideDateTime();
gs.print(startDate.getDisplayValue());
var fullDur = gr.duration.getGlideObject()
var schedule = new GlideSchedule(gr.schedule);
var end = schedule.add(startDate, fullDur);
return end;
}
}
gs.print((setDueDate.CalculateDueDate("270ef00cd7133200bbc783e80e6103f1")).getDisplayValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 01:02 PM
Are you in the "US/Pacific" time zone?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 01:09 PM - edited ‎02-22-2024 01:10 PM
Yes, we are in California.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 01:38 PM
It feels like a time zone issue because its off by just 1 hour.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 02:23 PM
Well I verified the schedule is set to US/Pacific and I have also tried both scripts without US/Pacific in the line below.
var schedule = new GlideSchedule(gr.schedule, 'US/Pacific')

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 03:04 PM - edited ‎02-22-2024 04:04 PM
Its not just an hour off. I just submitted the catalog item that has a 9 hour SLA. So my due date should be somewhere around 3 PM tomorrow but the script is coming back at around 1 pm.
Edit: correction its showing as 1 AM not PM like it should.