BLOG : DeleteRecord() vs DeleteMultiple()

SriharshaYe
Mega Sage

deleteRecord() and deleteMultiple() are GlideRecord methods in ServiceNow for deleting records from tables. The first targets a single record, while the second handles bulk deletion based on query conditions
DeleteRecord():
deleteRecord() 
performs to delete a single record from a table. It is invoked on a GlideRecord object that points to the specific record you want to delete.

Example —

var inc = new GlideRecord(‘incident’);
if (inc.get(‘sys_id_of_record’)) {
inc.deleteRecord(); // Deletes the specific record
}

DeleteMultiple():

deleteMultiple() performs to delete multiple records from a table based on the query conditions defined in the GlideRecord object. It is invoked on a GlideRecord object with a query specifying the records to delete.

This method does not delete attachments.

Do not use deleteMultiple() on tables with currency fields. Always delete each record individually. Also, do not use this method with the chooseWindow() or setLimit() methods when working with large tables. The setLimit() method does not limit the number of records that are deleted with deleteMultiple(). All records returned by the query are deleted regardless of setLimit().

Example —

var inc = new GlideRecord(‘incident’);
inc.addQuery(‘priority’, ‘3’);
inc.query();
inc.deleteMultiple(); // Deletes all records with priority 3

0 REPLIES 0