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

Robbie
Kilo Patron
Kilo Patron

Hi Matthew,

Can I ask why you have a 'Fix SLA' functionality or script? Is this simply a one off exercise?

I would steer you toward the SLA(s) itself and configure the stop time accordingly. That way a script is not required. (You will however need to run a fix for any 'in-flight' and previously closed records however. I would also advise confirming with the business and flagging that this as it will update existing reports)

Here's an example of an SLA. (Out of box). Note the 'Stop condition' tab and how the 'Stop time' is driven.

You could update this to state Resolved.

Please also find below updated script for in flight / historic tickets.

To help others, please mark correct and/or helpful.


Thanks,
Robbie

find_real_file.png

 

Script: (Updates in bold)

var tab = new GlideRecord('task_sla');
//Searches for the affected incident SLAs
tab.addQuery("sys_id", "92517e302f3941106e47cfedf699b60a");
//Runs the query
tab.query();
//While it's looping through the records
while(tab.next()){
tab.end_time = tab.task.resolved_at;
//Helps in prevent running of BR's while updating
tab.setWorkflow(false);
//gs.log('found: ' +tab.task.number + ' resolved at: ' + tab.task.resolved_at + ' end time: ' + tab.end_time); //used for testing
tab.update();
}

Hi Robbie. This is a one off exercise because some of our incidents didn't have their Task SLA 'Stage' set to 'Paused' when the caller set their incident to 'Resolved'. The issue was caused by a business rule that we amended, but we've reverted it back to prevent other incidents being affected. So what my script is trying to do is search for those affected task SLAs and update the Stop Time to match the Resolved Time from their related incident.

 

Is it also possible to add the SLA repair function to the script as well?

Hi Matthew,

Here's an updated script that searches through the Task SLA's and provides the result set we're interested in (Rather than loop through all Task SLA's.)

(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)

I would create this as a 'Fix Script' but you could also create this as a script include and call it from the Fix Script or other scripts/code moving forward.

To help others, please mark correct and/or helpful.


Thanks,
Robbie

var total = 0; //Counter used for testing. Confirming total number of records
var count = 0; //Counter used for testing. Confirming how many records to update
//Searches for the affected incident SLAs
var tab = new GlideRecord('task_sla');
tab.addEncodedQuery('end_timeISNOTEMPTY');
tab.addQuery('task.sys_class_name', 'incident');
//Runs the query
tab.query();
//While it's looping through the records
while(tab.next()){
//Only query/update records where SLA stop time and related Incident Resolved time are different
if(tab.end_time.getDisplayValue() != tab.task.resolved_at.getDisplayValue()){
//Helps in prevent running of BR's while updating
gs.log('found: ' +tab.task.number + 'SLA Def:' + tab.sla.name + ' SLA stop time: ' + tab.end_time.getDisplayValue() + ' inc resolved at: ' + tab.task.resolved_at.getDisplayValue()) ; //used for testing
tab.end_time = tab.task.resolved_at;
tab.setWorkflow(false);
//tab.update(); //Uncomment when you have confirmed the correct records are to be updated
count++;
}
total++
}
gs.log('Count:' + count + 'Total:' + total);

Hi Robbie, I appreciate that the script updates the Stop Date to the new Resolved Date, but how would I implement the fix SLA functionality within that script?