Delete All Records Does Not Delete All Records

johndurden
Kilo Contributor

I've done some searching on the community and elsewhere hoping to find someone else talking about this issue we're having, but I'm not finding anything. Fairly often we need to delete all the records from some tables. In the current situation, there are 115,000 records we need to delete. When go to Tables & Columns > choose the table > click "delete all records", it works for about 5 minutes, then stops. I receive no errors or feedback. It just stops deleting records and it has to be restarted.

 

The fact that it's taking right around 5 minutes every time makes me think it's a 5 minute timeout. But I don't see a system property for that. Maybe I just need some educating on this. What's going on here? Is there a quicker or better way to delete all the records from tables?

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Its likely Transaction Quotas that are "killing" the transaction.   You can verify by searching the logs for message contains "maximum execution time exceeded" as mentioned in the Docs article.


View solution in original post

10 REPLIES 10

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Its likely Transaction Quotas that are "killing" the transaction.   You can verify by searching the logs for message contains "maximum execution time exceeded" as mentioned in the Docs article.



Consider the following guidelines when deleting the records:


  • Limit the number of records to be deleted in a single delete action to prevent the table from being locked. Use the setLimit() method described at setLimit.
  • Minimize triggering an excessive amount of business rules as a result of this deletion. Use the setWorkflow(boolean e) method described at setWorkflow.


you can use below script in scheduled and run when you want to delete the records:




  1. deleteIncRec();  
  2. function deleteIncRec()  
  3. {  
  4. var rec = new GlideRecord('incident');  
  5. rec.setLimit(1000);  
  6. rec.query();  
  7. while (rec.next()) {  
  8.   //gs.print('Inactive incident ' + rec.number + ' deleted');  
  9.   rec.setWorkflow(false);  
  10.   rec.deleteRecord();  
  11. }  
  12. }  

shruti_tyagi
ServiceNow Employee
ServiceNow Employee

Hi John,



5 minute timeout can be due to 5 minute quota rules we have for user transactions. For deleting large number of records I would recommend to add this table for table cleanup and let scheduled job do the cleanup for you. Check this detailed explanation by scott:



https://community.servicenow.com/message/1162199#1162199



Thanks


Shruti


If the reply was informational, please like, mark as helpful or mark as correct!


So the "Delete All Records" button should really say "Delete As Many Records As You Can In Five Minutes"? I would understand this is the case if I was doing this from a UI Action that wasn't out of the box, but that's not the case here. Are you saying that the OTB "delete all records" button is held to the same limitations as UI Actions I create?