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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 06:27 AM
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;
What we would like to happen when the 'Repair SLAs' function is ran:
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 05:19 AM
Hi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 05:42 AM
Hi Matthew,
I covered this in my latest script that provided the result set of Task SLA's for Incidents, where we have a stop date/time and that stop date/time is not equal to the related incident resolution time.
Assume you no longer need any help as I've written a few responses without acknowledgement.
Remember - despite include 'sertWorkflow(false)' ,test this in sub prod to avoid any unknowns such as event triggered by the RepairSLA.
Hope you found your answer.
Please can you mark correct and my previous responses as helpful. This helps others with similar questions and improves the knowledge base.
Thanks,
Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 07:13 AM
Hi
As always, give it a thorough testing on a small set of records in an isolate instance like a PDI..
Script:
var tab = new GlideRecord('task_sla');
tab.addEncodedQuery(
'task.numberLIKEinc^task=46e18c0fa9fe19810066a0083f76bd56^ORtask=46e8219ba9fe1981013806b6e04fed06^ORtask=46f4f4dfa9fe198100063e60278f76ec^ORDERBYDESCsys_created_on'
);
tab.query();
while (tab.next()) {
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();
tab.setWorkflow(false);
var repair = new SLARepair();
repair.repairByGlideRecord(tab);
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();
}
}
Hope that helps.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 02:01 AM
Hi
Did it work?
Cheers
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 02:18 AM
Hi Dan,
After a meeting with colleagues, we've decided not to go ahead with this because this would mean updating the log history, and we're not allowed to do that. I do appreciate your help with this.