- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 10:31 PM
Need a script to delete the bulk data from tables in servicenow ? EX : RITMS, USERS,TEST TICKETS etc..
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 10:39 PM
Hi Karthick,
I hope this post may help you Remove Demo Data from your Instance without submitting an Incident
and you can try this too
Name: Remove All Data from a Table
Type: Background Script.
Table: Specified in the function parameter.
To run this script:
Navigate to System Definition > Scripts - Background.
Change table_name in the script to the name of the table you want to delete all records from.
Script:
doit("table_name");
//for example doit("cmdb_ci");
function doit(table) {
var gr = new GlideRecord(table);
gr.query();
gr.deleteMultiple();
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 10:39 PM
Hi Karthick,
I hope this post may help you Remove Demo Data from your Instance without submitting an Incident
and you can try this too
Name: Remove All Data from a Table
Type: Background Script.
Table: Specified in the function parameter.
To run this script:
Navigate to System Definition > Scripts - Background.
Change table_name in the script to the name of the table you want to delete all records from.
Script:
doit("table_name");
//for example doit("cmdb_ci");
function doit(table) {
var gr = new GlideRecord(table);
gr.query();
gr.deleteMultiple();
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 11:25 PM
Thank you Farhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 07:38 AM
Before using deleteMultiple() we don't need (and it's not a good practice) to use the query() function (the deleteMultiple will do the query) 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2016 10:44 PM
Hi Karthik,
The simplest method is in the Tables and Columns module. Navigate to Tables and Columns> Find you table and click on delete All records.
This will actually run the deleteAllRecords business rule ( you can also use this code based on your need) which performs a deleteRecord call on each record.
Also, you can do this from the List menu, Click on Show number of records and then select all rows from a page, this may take time as you have to go from several page lists.
For reference:
Deleting All Records from a Table - ServiceNow Wiki