- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2017 08:47 AM
Hi,
I need to set up some SLA(s) where the clock runs 24x7, but the SLA threshold varies according to the time of day.
i.e.
A. Logged/Created During working hours, SLA is 30 mins - and the clock runs 24x7
(otherwise I understand the clock would pause when we go out of hours for a ticket logged very close to the end of working hours)
B. Logged/Created Outside working hours, the SLA is 2 hours - and the clock runs 24x7.
How might I do this?
I've been fishing about with Relative times - and I THINK I could go from 'zero to breached' in an instant by setting the StartTimer to have a retrospective start and monitor the Created Time as being At of before 2 hours ago. -but... that doesn't allow for workflow processes to send reminders at 50% of the time etc.
Any suggestions?
cheers
Martin
p.s. I'm a novice, so please excuse any newbie mistakes.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2017 09:02 PM
Hi,
You can easily achieve this by using a relative duration.
Sample script for the relative duration would look like:
var inSchedule = new GlideSchedule("08fcd0830a0a0b2600079f56b1adb9ae").isInSchedule(new GlideDateTime());
if (inSchedule) {
calculator.calcDuration(30*60);
}
else {
calculator.calcDuration(2*60*60);
}
The logic is pretty simple:
1. Have a pre-defined schedule that gives you the working hours and non-working hours. Get the SysId of that Schedule. In this example I have used the OOB 8-5 weekdays.
2. Use the GlideSchedule API to initialize the schedule and understand if the current time is in Schedule (within working hours) or not.
3. If within schedule (working hours), set the due date to be 30 minutes from now. If not within the schedule, set the due date to be 2 hours away.
Note: We need to use the calculator object that is available OOB in the Relative Duration script include. Use the calcDuration API to add the number of seconds relative to current time.
You can then use this relative duration in the SLA Definition. Ensure to set the "Schedule source" in SLA Definition to "No Schedule", else as you mentioned earlier, the Task SLA will pause once it gets into out of business hours.
I am attaching the sample XML files for the Relative Duration and SLA Definition. You can tweak these to suite your business needs. Instead of hard coding the schedule, you can derive the value at run time from the Task table or any of the fields on the Task that have a schedule specified on them. Ex: Caller, etc.
I have tested this in my local instance, and it works fine. Let me know if you face any issues.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 01:29 AM
Dear Aditya
I am fairly new to servicenow and have somewhat similar need to calculate sla based on ticket open time.
is your solution still valid in London release ? I tried to import xmls you attached but was not successful on a dev instance.
Also I am not sure wats the right place for sample script you mentioned.
I hope you have some time to clarify on this old post 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 01:47 AM
dear Aditya
I am fairly new to Servicenow and I have a similiar need to caculate sla based on ticket open time.
I was wondering if your solution is still relevant in London release, can you confirm that ?
Also I tried to import xmls you have provided for SLA and schedule but it didnt work on a developer instance.
Also I am unsure about the sample script your have provided, where exactly that script should run ?
in a business rule ?
I hope you have some time to clarify this 🙂