- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 01:12 PM
We have a new sub-prod instance that has been cloned from prod, but there is a request to removed 11 yrs of history from this instance. I have a BG Script running but its taking an hour to delete 100 records. I have over 2m records to remove. Any thoughts or scripts to quickly wipe out all records on a table? Here's what I'm running.
var rec = new GlideRecord('incident');
rec.query();
while (rec.next()) {
gs.print('Inactive incident ' + rec.number + ' deleted');
rec.deleteRecord();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2017 06:40 AM
In working with ServiceNow, here is the option they suggested I try:
Navigate: Automated Test Framework > Administration > Table Cleanup
- Click New
- Tablename: <table to delete records>
- Age in seconds: 1 day's worth of seconds (60x60x24 = 86400) or a week or whatever you want to keep
- Cascade delete: true (that way it will clean up other data)
- Then there are more conditions you can add.
- Click Submit
Let the scheduled job Table Cleaner run it's schedule. To check and verify there is a scheduled job.
Navigate: System Scheduler > Scheduled Jobs
- Search Name: Table Cleaner
*Note the Next Action Date/Time
If the scheduled job does not exist - create a new job to repeat every hour, but this is an OOB job and should exist.
Once the scheduled job has run and completed - DELETE THE TABLE CLEANUP you created. If not, you will continually delete the records from the table.
I was able to delete 1.8m records in about 6 hours.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 01:21 PM
The previous releases prior to Geneva (i guess) allowed you to execute SQL queries from the background script but it has been restricted now. The deleteRecord can even take a whole day to complete with large number of records. I believe HI support could help you in clearing the data from backend database as they can run the queries directly.
Thank You
Please Hit Like, Helpful or Correct depending on the impact of response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 01:23 PM
I think you could have excluded the table when clone back was performed if the data was not required
http://wiki.servicenow.com/index.php?title=System_Clone#Excluding_Tables_from_Cloning
Thank You
Please Hit Like, Helpful or Correct depending on the impact of response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 01:26 PM
Hi Scott,
So you are deleting everything in incident table, thats wat your script is doing?
var rec = new GlideRecord('incident');
rec.query();
while (rec.next()) {
gs.print('Inactive incident ' + rec.number + ' deleted');
rec.deleteRecord();
}
If you want to delete everything there are few options:
1. Delete from Tables & Columns or Delete from List view:
2. Or just do deleteMultiple, will be faster as compared to while loop in deleteRecord:
Function deleteInc() {
var rec = new GlideRecord('incident');
rec.query();
rec.deleteMultiple();
4. If you dont want to delete everything in incident table, add where condition. The field on which you add where condition make sure its indexed in database.
http://wiki.servicenow.com/index.php?title=GlideRecord#Delete_Methods
5. Last option is to have CS delete all records from incident table from backend. This will be faster, create ticket in HI.
Hope this will help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2017 06:40 AM
In working with ServiceNow, here is the option they suggested I try:
Navigate: Automated Test Framework > Administration > Table Cleanup
- Click New
- Tablename: <table to delete records>
- Age in seconds: 1 day's worth of seconds (60x60x24 = 86400) or a week or whatever you want to keep
- Cascade delete: true (that way it will clean up other data)
- Then there are more conditions you can add.
- Click Submit
Let the scheduled job Table Cleaner run it's schedule. To check and verify there is a scheduled job.
Navigate: System Scheduler > Scheduled Jobs
- Search Name: Table Cleaner
*Note the Next Action Date/Time
If the scheduled job does not exist - create a new job to repeat every hour, but this is an OOB job and should exist.
Once the scheduled job has run and completed - DELETE THE TABLE CLEANUP you created. If not, you will continually delete the records from the table.
I was able to delete 1.8m records in about 6 hours.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 06:01 AM
I tried it and it is as slow as a glideRecord deleteRecord(); or deleteMultiple();
So far there is no quick mass delete solution with conditions...