"Breach on Due Date" SLA Breaching Instantly

Nick Peters
Tera Guru

I am trying to create an SLA on the Requested Item table that breaches on the Due date. Here is the SLA Definition:

find_real_file.png

The problem I'm having is that the SLA is breaching instantly (or rather, exactly 1 second after it starts); which is exactly what the duration script says it will do if it can't find the due date field. But I find this odd because I'm using the OOB "Breach on Due Date" relative duration option and the OOB Due date field on the OOB RITM table.

Any help would be appreciated. Thank you!

3 REPLIES 3

Tommy SN Sahlin
Kilo Sage

Hi Nick,

Out of curiosity, I just tried it on my personal instance and it worked fine for me.

Are you sure the date/time formats haven't been messed with, or the script for calculating breach time?

good luck  /Tommy

Nick Peters
Tera Guru

Digging into the code for the Breach on Due Date relative duration script, I found the issue. Here's the OOB code:

/* 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);
       dueDate.addSeconds(1);
  }

  // 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;
  calculator.calcScheduleDuration();
})();

startDateMs is using getNumericValue() which will return the number of milliseconds from 1/1/1970 based on the current date AND time. dueDate is using dateNumericValue() which will return the number of milliseconds that the current date is from 1/1/1970 based only on the current date. This is really strange given that the Due date field is a Date/Time field.

So if the due date is on the same day as the start date, the SLA will breach instantly because with these numbers it appears as if the due date is in the past.

dmathur09
Kilo Sage
Kilo Sage

Hi Nick,

It can not determine the Duration. As the Duration Type is "Breach on due date". Hence you are not filling any value in Duration field. As it is taking the a default value of 0 seconds.

If you select Duration Type as "User Specified Duration". Then filling any value in duration field, it will then show the given value.

Regards,

Deepankar Mathur