Best way to delete multiple record in servicenow

MK-p
Tera Contributor

Hi,

 

I want to delete around 20k record, could you please help me the best way to do so. I don't want to make my system slow during deletion.

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @MK-p ,

 

My recommendation would be instead of deleting those record you can archive it. Benefit of archive is you can refer any point of time in future and if these records are not relevant to your client then you can use below code to delete.

 

Create a fix script and use below code.

 

var grObj = new GlideRecord('your_table_name');
grObj .addEncodedQuery('your_encoded_query'); // Specify the condition for the records to delete
 grObj .deleteMultiple();

//For Example
//if i want to delete all incident having no short description then my code would be like this.
var incGr = new GlideRecord('incident');
    incGr.addNullQuery('short_description');
    incGr.deleteMultiple();

 

 

 

Please Mark Correct if this solves your query and also mark Helpful if you find my response worthy based on the impact.

Regards,

Runjay Patel 

View solution in original post

2 REPLIES 2

Najmuddin Mohd
Mega Sage

Hi @MK-p ,

The best way, ServiceNow introduced Delete Jobs (module name). Using it you can select the table and filter the table.
Clicking Execute now, will delete the records.

The best thing is, it is best way when compared to scripts. The system does not slow down.


If the above information helps you, Kindly mark it as Helpful.
Regards,
Najmuddin.

Runjay Patel
Giga Sage

Hi @MK-p ,

 

My recommendation would be instead of deleting those record you can archive it. Benefit of archive is you can refer any point of time in future and if these records are not relevant to your client then you can use below code to delete.

 

Create a fix script and use below code.

 

var grObj = new GlideRecord('your_table_name');
grObj .addEncodedQuery('your_encoded_query'); // Specify the condition for the records to delete
 grObj .deleteMultiple();

//For Example
//if i want to delete all incident having no short description then my code would be like this.
var incGr = new GlideRecord('incident');
    incGr.addNullQuery('short_description');
    incGr.deleteMultiple();

 

 

 

Please Mark Correct if this solves your query and also mark Helpful if you find my response worthy based on the impact.

Regards,

Runjay Patel