How can we delete duplicate records?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 09:20 PM
How can we delete duplicate records from incident table using background script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 09:29 PM - edited 02-01-2024 09:30 PM
Hi @Supriya P below script should do
var inc= new GlideAggregate('incident');
inc.groupBy('number'); // group by number
inc.query();
while (inc.next()) {
var inc1= new GlideRecord('incident');
inc1.addQuery('number', inc.number);
inc1.query();
inc1.next(); // Skip the first result
while (inc1.next()) { // delete the next one
gs.info(inc1.number);
inc1.deleteRecord();
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 10:53 PM
Hi @Supriya P ,
please refer the below link.
Mark my answer as accepted solution and helpful if helps you.
Thanks,
Nivedita Patil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 10:55 PM
Hello @Supriya P ,
Give a try to the script below and see how it works for you.
var inc = new GlideAggregate('incident');
inc.groupBy('short_description', 'description'); // group by multiple fields
inc.query();
while (inc.next()) {
var inc1 = new GlideRecord('incident');
inc1.addQuery('short_description', inc.short_description);
inc1.addQuery('description', inc.description);
inc1.query();
inc1.next(); // Skip the first result
while (inc1.next()) { // delete the next one
gs.print('Deleting duplicate incident with number: ' + inc1.number);
inc1.deleteRecord();
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 12:20 AM
Thank you all!
Tried below script and issue solved
var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_created_onRELATIVELT@minute@ago@30');
gr.query();
while(gr.next()){
gr.deleteMultiple();
}