The CreatorCon Call for Content is officially open! Get started here.

Need a script to delete the bulk data from tables in servicenow ? EX : RITMS, USERS,TEST TICKETS etc..

katz2
Tera Contributor

Need a script to delete the bulk data from tables in servicenow ? EX : RITMS, USERS,TEST TICKETS etc..

1 ACCEPTED SOLUTION

syedfarhan
Kilo Sage

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


View solution in original post

7 REPLIES 7

syedfarhan
Kilo Sage

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


katz2
Tera Contributor

Thank you Farhan


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) 😉

Kushagra Mehrot
Kilo Guru

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