Cancelling Existing Incident SLAs and Attaching New Ones
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Most of the time when amending existing SLAs you can simply amend the existing SLA with an end date/time Start condition and put a new date/time Start Condition on the new SLA version, but sometimes you may need to completely cancel and attach a set of different SLAs for example when a contract is totally renegotiated. Well this script will do that for you:
(function() {
try {
gs.info(‘Starting batch SLA fix process…’);
```
// Query for incidents that need SLA fix
var incGR = new GlideRecord('incident');
incGR.addQuery('active', true);
incGR.addQuery('state', '!=', 6); // Not closed
incGR.addQuery('state', '!=', 7); // Not cancelled
// Add additional query conditions as needed
// Example: incGR.addQuery('assignment_group', 'specific_group_sys_id');
incGR.query();
var processedCount = 0;
var totalApplied = 0;
while (incGR.next()) {
gs.info('\n--- Processing: ' + incGR.number + ' ---');
// Cancel old SLAs
var taskSLAGR = new GlideRecord('task_sla');
taskSLAGR.addQuery('task', incGR.sys_id);
taskSLAGR.addQuery('active', true);
taskSLAGR.query();
var cancelledForThis = 0;
while (taskSLAGR.next()) {
taskSLAGR.active = false;
taskSLAGR.stage = 'cancelled';
taskSLAGR.update();
cancelledForThis++;
}
gs.info('Cancelled ' + cancelledForThis + ' SLA(s)');
// Trigger SLA recalculation using TaskSLAController
gs.info('Triggering SLA attachment...');
var slaController = new TaskSLAController();
slaController.attach(incGR);
gs.sleep(1000); // Brief pause for processing
// Count applied SLAs
var appliedSLAGR = new GlideRecord('task_sla');
appliedSLAGR.addQuery('task', incGR.sys_id);
appliedSLAGR.addQuery('active', true);
appliedSLAGR.query();
var appliedForThis = appliedSLAGR.getRowCount();
gs.info('Applied ' + appliedForThis + ' new SLA(s)');
totalApplied += appliedForThis;
processedCount++;
}
gs.info('\n==================================================');
gs.info('Batch processing complete!');
gs.info('Processed ' + processedCount + ' incident(s)');
gs.info('Total SLAs applied: ' + totalApplied);
gs.info('==================================================');
} catch (e) {
gs.error('Error in batch SLA fix: ' + e.message);
gs.error('Stack trace: ' + e.stack);
}
```
})();
Hope this helps anyone who finds it
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Appreciate your efforts to write a new script to handle the retagging of the SLA's.
But as per my knowledge, we already have that feature in SLA. We can always edit the conditions like Start, Cancel to when to pause SLA, cancel SLA and add a new SLA.
For eg. If I am routing the Task to some other group, we can always have a start condition and cancel condition based on the groups.
Regards,
Nayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Think you are missing the point, this isn't about updating existing SLAs, but replacing them with new ones that have different contractual conditions. In this circumstance you need to mass cancel existing SLAs running on existing active tickets and reattach new ones. As I said in the post 'Most of the time when amending existing SLAs you can simply amend the existing SLA with an end date/time Start condition and put a new date/time Start Condition on the new SLA version'
Regards
Paul
