How to use deleteMultiple
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 04:08 PM - edited 07-29-2023 04:09 PM
Hi Team,
kindly help me on how to use deleteMultiple, which is best practice.
var gr = new GlideRecord('incident');
gr.addQuery('activ=false');
gr.query();
if(gr.next())
{
gr.deleteMultiple();
}
OR
var gr = new GlideRecord('incident');
gr.addQuery('activ=false');
gr.query();
gr.deleteMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 04:31 PM
the 2nd one is the best practice for multiple deletion.
For example:
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', gs.getUserID() );
gr.query();
gr.deleteMultiple();
THis is to delete all incidents where caller was logged in user.
This gives you a great performance as we will not be iterating over the GR object.
The 1st one will have a performance degradation because you are iterating over object and then delete it.
You can also refer to following article for more understanding:
By the way script added in your example have spelling mistake of active as field name and you need to user encoded query instead of add query, correct line as following:
gr.addEncodedQuery('active=false');
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 04:37 PM - edited 07-29-2023 04:37 PM
why don't we use ??? below one
if i Use what is the issue ?
var gr = new GlideRecord('incident');
gr.addQuery('activ=false');
gr.query();
if(gr.next())
{
gr.deleteMultiple();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 12:55 AM
Hi @Supriya25
The script you provided here has mistake.
instead of gr.addQuery('activ=false'); you need to correct here like gr.addEncodedQuery('active=false'); OR gr.addQuery('active',false); .
Now coming below you have used if instead of while , IF will delete just one record where as While will iterate over all set and delete all the active=false records.
Now how to use deleteMultiple() or deleteRecord() for deletion you can refer following for best practice:
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 06:04 PM
You don't need to call .query() or .next().
Example: