Running a fix script to update the stop time to be the resolve time of an incident and then resolve the SLA

matthew_hughes
Kilo Sage

I'm trying to create a fix script that will search for incidents created at a certain time where their task SLAs have been breached, take the Resolve time from each incident and update this in the Close time on any associated SLAs, and then repair the associated SLAs of each incident. I've written the below fix script and was just wondering if this would cover the scenario:

var tab = new GlideRecord('task_sla');
//Searches for the affected incident SLAs
tab.addEncodedQuery('task.sys_created_onONThis year@javascript:gs.beginningOfThisYear()@javascript:gs.endOfThisYear()^task.ref_incident.caller_idSAMEAStask.ref_incident.resolved_by^task.ref_incident.resolved_atBETWEENjavascript:gs.dateGenerate('2022-02-03','18:00:00')@javascript:gs.dateGenerate('2022-02-09','18:30:00')^has_breached=true');
//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()){
//Sets the 'Stop time' field to match the resolved field in the related incident
end_time = task.ref_incident.resolved_at;
//Makes the update
tab.update();
}
var repair = new SLARepair();
while (now_GR.next())
repair.repairByGlideRecord(tab);

 

If there is anything that needs changing or if there's a better way of doing this, please let me know.

16 REPLIES 16

What I noticed when running the script is that it deletes the current task SLA entry and ten creates another one using historic data.

Hi @Dan H Is it possible that we would have to change a script include within our instance to update the 'Stop Time' on the Newley created SLA task after the 'Repair SLA' action has been carried out?

Hi Matthew,

I would say probably a new business rule or script include.

At this point, is the requirement just to populate the stop time field on the newly inserted Task SLA record after it was repaired? Are you okay with how the script is initially setting the stop time in the field and then reparing the SLA? have you confirmed that the new SLA Task created has the data you would expect apart from the missing value for Stop time?

Hi Dan,

 

So the requirement is that on the current SLA tasks, they get their Stop Date updated to match the Resolved Date of the related incident. Then the idea is that when the Fix SLA part of the script is run, that would create the new SLA task entry with the Stop Date matching the new Resolved Date rather than reverting to the date and time the incident was originally closed.

Hi @Dan H I've attached some screenshots of the ideal scenario in my other question

Is it possible to update the Stop Date of a task SLA to match the Resolve Date of an incident record...