- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 01:37 AM
Hi,
Could any one please guide me on how to delete all records from cmdb_ci_computer table using Glide Record query?( I have tried using "Delete all Records" By going to Tables and Columns but it is not deleting all records at once.)
Thanks and Regards,
Sharada.
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 02:06 AM
HI Sharada,
A quicker way to do this would be use a direct SQL command to truncate the entire data, it will be done really fast and no record will be left behind in that table. Run the following command in the Scripts - Background:
gs.sql("truncate table <table_name>");
Hope this helps
Thanks & Regards,
Hari

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 01:53 AM
Hi Sharada,
Here is the script
var rec = new GlideRecord('cmdb_ci_computer');
rec.query();
while (rec.next()) {
gs.print('Inactive incident ' + rec.number + ' deleted');
rec.deleteRecord();
}
Thanks,
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 01:10 PM
Thought I would just drop this here because I found this really useful in a similar situation.
doit("table_name");
//for example doit("cmdb_ci");
function doit(table) {
var gr = new GlideRecord(table);
//gr.addEncodedQuery("");
gr.query();
gr.deleteMultiple();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 10:57 PM
Hi Jeff,
That's a good catch - however there are a few caveats using that method, as documented in the Developer API Documentation:
https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_GlideRecord-deleteMultiple
deleteMultiple()
Deletes multiple records according to the current "where" clause.
This method does not delete attachments.
Dot-walking is not supported for this method. When using the deleteMultiple() function on referenced tables, all the records in the table will be deleted. Also, when using deleteRecord() to cascade delete, prior calls to setWorkflow() on the same GlideRecord object are ignored.
Do not use deleteMultiple() on tables with currency fields. Always delete each record individually.
To use the deleteMultiple() method in a scoped application, use the corresponding scoped method: deleteMultiple().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2014 02:06 AM
HI Sharada,
A quicker way to do this would be use a direct SQL command to truncate the entire data, it will be done really fast and no record will be left behind in that table. Run the following command in the Scripts - Background:
gs.sql("truncate table <table_name>");
Hope this helps
Thanks & Regards,
Hari