Dynamically setting SLA Duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2016 09:22 AM
I have a requirement to set the SLA Duration by a Target Date field (u_target_date) from a Problem ticket.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2016 05:56 AM
I haven't tested doing something like this, but in this KB there is an example of a script that might possibly work: ServiceNow KB: PRB575361: SLA definitions using relative durations do not set "current" consistently...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2016 06:02 AM
I ended up doing a metric and they were happy. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 01:55 AM
If you want to have SLA's Planned End Time (Breach Time) to be set to a particular value defined in a date-time field of current object, you can create Relative Duration and use DurationCalculator's method "calcScheduleDuration" for that. This methods receives two parameters "start time" and "end time" and calculates correctly the seconds that are available within that timespan for SLA.
calculator.calcScheduleDuration(calculator.startDateTime, current.u_target_date);
Just make sure you have correct object available under the "current" variable as it might be task or task_sla - depending on the setup of your SLA definition. But you can implement there simple check for current's class and have different way to get the target date then.
Also consider handling the scenario when u_target_date is outside the schedule defined for the SLA. In such case you might want to amend the calculation little bit to move backwards to the end of last schedule span so that Breach Time is not outside the business hours.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2017 07:13 AM
I am trying to achieve the same thing - when a user selects a specific date in the service catalog I have used a relative duration to set the sla breach date at 5pm. Yesterday afternoon at 2017-03-07 17:55:00 I entered a date of 2017-03-13 (requested date) and the sla breach was 2017-03-10 17:00:00. *two days off
I again entered a ticket at 2017-03-07 17:59:05 and entered a date of 2017-03-17 (requested date) and the breach date was 2017-03-16 17:00:00 * one day off.
i am thinking it has to do with my difDays calc. Any advice?
//This script will set the end date to the SLA the day requested at 5pm
var startDateTime = new GlideDateTime();
var endDateTime = new GlideDateTime(current.variables.requested_date + ' 17:00:00');
var diffSeconds = calculator.calcScheduleDuration(startDateTime, endDateTime);
//Dividing by 36000 (the number of seconds in a 7 - 5 business day)
var diffDays = Math.floor(diffSeconds / 36000);
calculator.calcRelativeDueDate(calculator.startDateTime, diffDays, "17:00:00");