difference between deleteRecord() and deleteMultiple()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 01:55 PM
Could you please help to understand the difference/uses between "deleteRecord" and "deleteMultiple".
Thanks in advance!!!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 01:56 PM
deleteRecord will delete single record and deleteMultiple will delete multiple.
lets say you are querying some table and get 10 records back and
if you want to delete all 10 at once you use deleteMultiple
if you want to delete one record at time then you use deleteRecord.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:13 PM
Thanks...
I am using below 2 scripts and after the query, 2000 records has to be deleted via both the scripts.
Noticing that the first script is taking way much time as compare to 2nd to delete a record.
var gr = new GlideRecord('test');
gr.addEncodedQuery('where mode = xyz');
gr.query();
while (gr.next()) {
gr.deleteMultiple();
gr.setWorkflow(false);
}
----------------------------------------------------
var gr = new GlideRecord('test');
gr.addEncodedQuery('where mode = xyz');
gr.query();
while (gr.next()) {
gr.deleteRecord();
gr.setWorkflow(false);
}
should I directly use the 2nd script? as both works for deletion only...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:16 PM
1st script needs be like
var gr = new GlideRecord('test');
gr.addEncodedQuery('where mode = xyz');
gr.setWorkflow(false);
gr.deleteMultiple();
also add gr.setWorkflow(false); before you do delete
Some benefits using deleteMultiple - https://snowunderground.com/blog/2019/8/18/deleting-fast-in-servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:05 PM
Please refer to API documentation:
it also depends where you want to execute, e.g. looping through a list of records that meet certain criteria and want to be tested further, you can put the gliderecord deleteRecord() within the while loop.
deleteRecord method does require that you execute the .query() first
deleteMultiple does not require this