We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to remove an SLA attached to historic data?

The Matrix
Tera Contributor

What is a best practice to remove an SLA attached to the record? 

5 REPLIES 5

Mark Manders
Giga Patron

What's your use case? Why would you want to remove Task SLA records from historic data? That's already done. If the SLA was incorrect, you could recalculate the SLA (repair) on the record, but do know that that will run on present definitions. Not on the ones active when the ticket was created.

 

Best practice on removing SLA records is: don't. Because it bad practice.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

yashkamde
Kilo Sage

Hello @The Matrix ,

 

remove means what? you want to change the stage to cancelled or delete the record totally from task_sla table?

If want to change the state to cancelled :

Use Bg :

var gr = new GlideRecord("task_sla");
gr.addQuery("sla", <sla definition sys_id>);
gr.query();
while (gr.next()) {
   gr.stage = "cancelled";
   gr.update();
   gs.print('success');
}

 

OR if want to delete the record from task_sla :

var gr = new GlideRecord('task_sla');
gr.addQuery('sla', '<sys_id sla definition>');
gr.query();
while (gr.next()) {
  gr.deleteRecord();
}

 

Note : You can remove SLA records from the task_sla table, but you cannot "unattach" them in a way that rewrites history without deletion..

If my response helped mark as helpful and accept the solution.

its_SumitNow
Mega Sage

Hi @The Matrix 

SLA records (Task SLA) are associated with tasks if the conditions are met, and deleting these records may affect reporting history and audit trails. The recommended procedure depends on the objective.

Option 1: Cancel the SLA (Recommended for Historic Data)

Cancel the task SLA record instead of deleting it.

To cancel the SLA:

Access the task SLA records (task_sla table).
Find the task SLA records.
Set the stage to 'Cancelled.'
This will stop the SLA from breaching or escalating, but the SLA record will be kept intact.

Option 2: Retroactively Delete Task SLA Records

To delete the task SLA record:

Access the task SLA records.
Filter the SLA definition and the relevant date range.
Use the 'Bulk Delete using List View' (right-click, select 'Delete', or write a background script).
Background Script:

 

javascript
var gr = new GlideRecord('task_sla');
gr.addQuery('sla.name', 'Your SLA Name');
gr.addQuery('created_on', '<', 'your_cutoff_date');
gr.deleteMultiple();

 

Regards

Sumit

Ankur Bawiskar
Tera Patron

@The Matrix 

but why to remove?

the table (task_sla) where info is stored about which SLA got attached to which Task can be used for reporting etc

You can try to archive that table if it's getting huge

Archiving | General Overview 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

 

 

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader