
- 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-23-2024 06:19 AM
So another thing I noticed is you did

- 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-23-2024 11:04 AM
That worked, I'm guessing not using gs.NowDateTime() in the one line was part of the solution too as I tried removed time zone before.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 11:07 AM
Correct, gs.nowDateTime returns the current date/time in the current users time zone and you need to do things in GMT. So you where basically accounting for the time zone twice.