Delete the duplicate records from incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 07:52 AM
Delete the duplicate records from incident table based on short description could you please help any one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 08:13 AM
Hi @vinod96 ,
Please try the below script in order to delete the duplicate records.
var gr1;
var gr = new GlideAggregate('incident');
gr.groupBy('short_description');
gr.query();
while (gr.next()) {
gr1 = new GlideRecord('incident');
gr1.addQuery('short_description', gr.short_description);
gr1.query();
gr1.next(); // Skip the first result
while (gr1.next()) { // delete the next one
gr1.deleteRecord();
}
}
Please mark my answer helpful & accepted if it helps you resolve your query.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 09:31 AM
this might help:
var gaDelete = new GlideAggregate('TableName'); // table on which deletion is to be performed
gaDelete.groupBy('XXXXXXX'); // column which you think has duplicate values
gaDelete.setLimit(10000)
gaDelete.query();
var grData;
while (gaDelete.next()) {
grData = new GlideRecord('table');
grData.addQuery('field', gaDelete.Field);
grData.query();
grData.next(); // Skip the first result
while (grData.next()) { // delete the next one
// gs.print(''whatver you want to output)
grData.deleteRecord();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2023 10:13 AM
Hi @vinod96 ,
Hope you are doing great.
To remove duplicate records from the incident table based on the short description, we can use a script to identify and delete the duplicates
var gr = new GlideAggregate('incident');
gr.addAggregate('COUNT', 'short_description');
gr.groupBy('short_description');
gr.addHaving('COUNT', '>', 1);
gr.query();
while (gr.next()) {
var dupGr = new GlideRecord('incident');
dupGr.addQuery('short_description', gr.getValue('short_description'));
dupGr.orderByDesc('sys_updated_on');
dupGr.query();
dupGr.next(); // Move to the second record
dupGr.deleteMultiple();
}
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 01:09 AM
Hi @vinod96 ,
Please refer the below link.
Mark my answer correct and helpful if helps you.
Thanks,
Nivedita Patil.