Set up an SLA for a Task's Due Date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2011 11:54 AM
I would like to create an SLA Definition that sets the Task SLA Planned end time equal to the Due date of the Task its attached to. I have already tried a Task SLA Business Rule that manually overrides the Planned end time value, but it appears the SLA is already calculating by the time I override it -- so altering the Planned end time has no effect. I have also tried to create a custom Relative Duration called "Use due date". It works most of the time, but unpredictably produces Planned end time values that are much sooner than the Task's Due date. Here is the script for the custom Relative Duration:
var d = current.task.due_date.getGlideObject(); var s = (d.getNumericValue() - (new GlideDateTime()).getNumericValue()) / 1000; calculator.calcDuration(s); current.planned_end_time = d;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2011 12:26 PM
Hey Guys,
I've been experimenting with this as well, and I managed to get it working in Demo, but so far I've been unable to get it to work in our own dev environment.
First, the field we want to use as the "end" is u_requested_date which is on the sc_request table. The SLA Definition using this Relative Duration script is similarly running off the sc_request table. u_requested_date is a date field, which you'll see I had to convert to datetime using the awesome gs.dateGenerate function.
var DueBy = gs.dateGenerate(current.task.u_requested_date,'00:00:00');
current.planned_end_time = DueBy;
calculator.endDateTime = DueBy;
var start = current.task.opened_at.getGlideObject();
calculator.seconds = ((calculator.endDateTime.getNumericValue() - start.getNumericValue()) / 1000);
calculator.totalSeconds = calculator.seconds;
gs.log('LOGME TASK ' + current.task.number + ' SLA SYS ID ' + current.sys_id + ' PET ' + current.planned_end_time + ' DUE BY ' + DueBy + ' ENTERED ' + current.task.u_requested_date);
I can get similar scripts to work on Demo, but not on my development system. It absolutely WILL NOT populate the planned_end_time field, even though my gs.log seems to output a proper value.
I set up the exact same script on a different sub-prod instance, and to my dismay, IT WORKED. The difference between the instances is that the "working" instance is using the original SLA engine, where as our development (non-working) instance is using the 2011 Engine.
Any ideas what might be going on?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2011 04:14 AM
R - Please log an incident with support, with all of the necessary details to reproduce it.
Demo is (usually) running the 2011 Engine too, but there is at least one defect (PRB561883, fixed in June 11 Patch 2, and later) that might lead to this (that wasn't the bug that was reported, and it would need some analysis to see if that's what's going on here, but it's conceivable that it could stem from the same root cause.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2011 06:45 AM
Hey James,
We opened up INT1946184 a few days back but haven't heard anything since.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2012 08:32 AM
The SLA always calculates planned_end_time based upon the SLA definition.
As you've noted, the one point you could influence this is with a relative duration script.
In the June 11 release, this is called from within TaskSLA()._recalculateEndTime():
_recalculateEndTime: function(totalPauseTimeMS) {
var dc = new DurationCalculator();
...
dc.calcRelativeDuration(this.taskSLAgr.sla.duration_type);
this.taskSLAgr.planned_end_time = dc.getEndDateTime();
},
and it then sets planned_end_time on the task_sla record.
You'll see in DurationCalculator().calcRelativeDuration() that it notes that the results of the calculation (which are normally performed in the relative duration script via calcRelativeDueDate()) are set in this.endDateTime and this.seconds. For completeness you would set this.totalSeconds, but the SLA code doesn't refer to that value.
You'll also see that 'this' (an instance of the DurationCalculator() class) is what is called 'calculator' in your script.
gc.putGlobal('calculator', this);
So, your calculator script would probably work with something like (untested):
var baseTable = new TableUtils(current.getRecordClassName()).getAbsoluteBase();
var myTask;
if (baseTable == 'task')
myTask = current;
else if (baseTable == 'task_sla')
myTask = current.task;
calculator.endDateTime = myTask.task.due_date.getGlideObject();
calculator.seconds = ((calculator.endDateTime.getNumericValue() - calculator.startDateTime.getNumericValue()) / 1000);
calculator.totalSeconds = calculator.seconds;
although you might only really need to set calculator.endDateTime, for SLA purposes.
[Edited: 24/01/2012, it's probably better to use calculator.startDateTime - the start time provided to the calculator - than assuming opened_at is appropriate. I've also realised that, for SLA purposes, sometimes 'current' is the task_sla record and not the task. So I've determined an appropriate contents for myTask and used that.]