Running a fix script to update the stop time to be the resolve time of an incident and then resolve the SLA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 12:31 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 12:59 AM
Hi i see a few changes needed in your while loop. I think you will also need to change the last 3 lines of the code you pasted as there is no reference/declaration of now_GR
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()){
var repair = new SLARepair();
tab.end_time = tab.task.ref_incident.resolved_at;
tab.update();
repair.repairByGlideRecord(tab);
}
Please mark answer helped/correct based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 02:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 05:18 AM
Hi Dan, so I need to try the above code on one or two incidents?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 05:25 AM
Hi Matthew,
You don't have to but it's a good idea to.
Fix scripts have rollback functionality, but I like to isolate a small set of records, say 1-3 incidents in this case and run the script on those.
Then I can check them manually and see everything worked as expected.
Then remove the restriction and run the script on all the records.