difference between deleteRecord() and deleteMultiple()

skumar_srbh
Tera Guru

Could you please help to understand the difference/uses between "deleteRecord" and "deleteMultiple".

Thanks in advance!!!

8 REPLIES 8

Jorn van Beek
Tera Guru

Difference is mainly in performance. This has to do with the underlaying SQL action.

on SQL, if you want to do a modification to a record (this includes delete action) the database does some commit checks for EVERY record you do this. If you do the action for multiple record in 1 order, then the SQL does the same commit checks but only once saving time.

So basicly if you need to delete 5 records, it wont matter that much, if you want to delete 20.000 records then using deleteMultiple can save you a lot of time.

 

I didn't even mention performance, whoops! Great post.

Bhagyashri Sort
Kilo Guru

Hi,

Please refer the below links

 

deleteRecord() & deleteMultiple()

deleteRecord() & DeleteMultiple()

 

Mark it Correct and Helpful, if my response helps you.

 

Thanks

Bhagyashri Sorte

Ganesh Pardhe
Kilo Guru

Hello Skumar,

PFB,

deleteRecord() and deleteMultiple()

These two methods are for the deletion of one or more records from the database.

It should be made clear that deletion of records in ServiceNow is, and should be, generally a rare occurrence. Whenever possible, it is best to deactivate or otherwise mark a record as no longer in use, for historical and tracking purposes.

Neither deleteRecord() nor deleteMultiple() take any arguments, as both are called as methods of a specific GlideRecord object upon which they act. However, the similarities end there, as the behavior and usage of both of these methods are quite different.

deleteRecord() is used to delete a single record (in a GlideRecord) from the database. deleteMultiple() on the other hand, is used to delete all database records that match a given query. However, it is important to remember this: Do not usedeleteMultiple() on tables that contain currency fields. Instead, delete all such records one at a time, using deleteRecord().

 

If my answer is worth to you please mark correct and helpful.

 

regards,

Ganesh