Is it possible to update the Stop Date of a task SLA to match the Resolve Date of an incident record whilst running Fix SLAs?

matthew_hughes
Kilo Sage

Hi,

On our instance we're wanting the 'Fix SLAs' functionality to update the Stop Time of the related Task SLAs to match the Resolved Date in the incident as the new Task SLA is created. I was just wondering if this was possible to do because at the moment, the Stop Time of a Task SLA matches the date and time when the incident gets set to 'Closed State'.

At the moment this occurs;find_real_file.png

 

find_real_file.png

find_real_file.png

 

What we would like to happen when the 'Repair SLAs' function is ran:

find_real_file.png

 

find_real_file.png

 

if somebody could please how I would need to implement the repair SLA function, but allow the Stop Date to match the Resolved Date, that would be great. My script is:

var tab = new GlideRecord('task_sla');
//Searches for the affected incident SLAs
tab.addEncodedQuery("task=1c741bd70b2322007518478d83673af3");
//Runs the query
tab.query();
//Helps in prevent running of BR's while updating
tab.setWorkflow(false);
//While it's looping through the records
while(tab.next()){
tab.end_time = tab.task.ref_incident.resolved_at;
tab.update();
}

20 REPLIES 20

Hi Matthew,

Circling back on this. How are you going?

I assume you've read and referenced the SLA Repair API documentation:

https://developer.servicenow.com/dev.do#!/reference/api/rome/server_legacy/c_SLARepair

Please can you mark correct and my previous responses as helpful. This helps others with similar questions and improves the knowledge base.

Thanks,

Robbie

 

Dan H
Tera Guru

Hi Matthew, 

Please test the following:

 

var tab = new GlideRecord('task_sla');
//Searches for the affected incident SLAs
tab.get('92517e302f3941106e47cfedf699b60a');
//Runs the query

//Helps in prevent running of BR's while updating
tab.setWorkflow(false);
//While it's looping through the records
if (tab) {
  //Get the incidents resolved_at time, the task sla's 'SLA sys id' and the sys id of the incident.
  var incidentSysId = tab.task.sys_id;
  var sla = tab.sla;
  var endTime = tab.end_time;
  tab.setValue('end_time', tab.task.ref_incident.resolved_at); //set resolved_at to end_time in SLA before repairing
  tab.update();
}

var repair = new SLARepair();
repair.repairByGlideRecord(tab);

//After repair, stop time is empty again on the new task sla
updateNewTaskSLA(incidentSysId, endTime, sla);

//function to set the incident resolved time into the new task sla
function updateNewTaskSLA(inc, endTime, sla) {
  var taskSLAGR = new GlideRecord('task_sla');
  taskSLAGR.addQuery('task', inc); //find the new task sla using the task field reference that was in the original task sla
  taskSLAGR.addQuery('sla', sla); //find the new task sla using the sla field reference that was in the original task sla
  taskSLAGR.query();
  if (taskSLAGR.next()) {
    taskSLAGR.end_time = endTime; //update the end tine ** end time may be slightly different to what is in INC resolved_at because of TIMEZONE of logged in user, but still valid.
    taskSLAGR.update();
  }
}

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Hi Dan,

 

Thanks for your help. When I apply that script to examples incidents, it clears out the 'Business elapsed time' and 'Business elapsed percentage' completely:

 

find_real_file.png

I wanted to check if it should be doing that because I can't see those two fields referenced in the script. 

 

find_real_file.png

 

This is the related task sla.

I have to do some more digging, because it hasn't done that for me.

before:find_real_file.png

 

after:find_real_file.png

 

Could you try on a few other incidents? I've also realised that once this solution works, it will need to be amended to handle multiple task_sla records at once, instead of just one.

 

After testing it again, it does seem to update the end date, delete the entry and then create a new entry with the end date as the resolved date from the incident. i will need to get this check with my colleagues.