It is possible to have an SLA Definition that creates Task SLA’s with a Breach time based on a date/time taken from the Task – for example the Due Date field which is available on all Task types.

This can be achieved by creating a Relative Duration which allows you to run a script to determine the SLA’s Breach time. You can then select this Relative Duration when defining your SLA Definition to replace the default User defined duration. The Duration always needs to return a static value, it cannot use gs.now or similar functions for calculations.

NOTE: Pause conditions are not supported for relative durations as these are viewed as providing a fixed date/time when the SLA should be met and as such the Breach time should not change.

You can create a new Relative Duration record by going to the Relative Durations module. An example of a script that would set the Breach time on the SLA to the date/time in the Due date field from the Task is:

/* This relative duration script will set the Breach Time of the Task SLA to the value in the "Due date" of the Task. 
   If the "Due date" field is available on the Task form and editable then this effectively allows the user to specify the 
   Breach Time of the SLA. 
   If the Due Date field is empty or in the past, the script will instead set the Breach Time of the SLA to 1 second 
   after the Start time 
(function() {  
  var startDateMs = calculator.startDateTime.getNumericValue();  
  var dueDate;  
  // Work out if "current" is a Task record or Task SLA and then get the "due_date" element from the Task  
  var tableName = current.getTableName();  
  if (tableName) {  
       var baseTableName = GlideDBObjectManager.getAbsoluteBase(tableName);  
       if (baseTableName == "task")  
            dueDate = current.getElement("due_date");  
       else if (baseTableName == "task_sla")  
            dueDate = current.getElement("task.due_date");  
  // if we've got a "due_date" and it's after our SLA's Start time then use it  
  // otherwise we'll have to default to the same as Start Time plus 1 second (i.e. instant breach of SLA)  
  if (dueDate && !dueDate.nil() && dueDate.dateNumericValue() > startDateMs)  
       dueDate = dueDate.getGlideObject();  
  else {  
       dueDate = new GlideDateTime(calculator.startDateTime);  
  // if we have a schedule then check if the Due Date is in it and if it isn't  
  // find the next time we are in the schedule  
  if (calculator.schedule && !calculator.schedule.isInSchedule(dueDate))  
       dueDate.add(calculator.schedule.whenNext(dueDate, calculator.timezone));  
  // set the endDateTime property of the calculator object to dueDate  
  calculator.endDateTime = dueDate;  

The example above includes defaulting Breach Time on the SLA to 1 second after the Start Time if the Due Date is empty or in the past.
If you created the example above with a name of Breach on Due Date then you would select this in an SLA Definition as shown below:


Article Information

Last Updated:2018-07-02 00:30:58