How to delete duplicate records in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 11:44 PM
How to delete duplicate records in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 07:03 AM
Hi @vbbfhg ,
I trust you are doing great.
Here's a basic example of how you might write a script to delete duplicate records. This example assumes you are dealing with duplicate incidents based on a similar field (like 'short_description'):
var gr = new GlideRecord('incident'); // Replace 'incident' with your table
gr.addAggregate('COUNT', 'short_description'); // Replace 'short_description' with the field you're checking
gr.groupBy('short_description');
gr.query();
while (gr.next()) {
if (gr.getAggregate('COUNT', 'short_description') > 1) {
var dupeGr = new GlideRecord('incident'); // Replace 'incident' with your table
dupeGr.addQuery('short_description', gr.short_description); // Replace 'short_description' with the field you're checking
dupeGr.query();
var i = 0;
while (dupeGr.next()) {
if (i != 0) { // Skip the first record, delete the rest
dupeGr.deleteRecord();
}
i++;
}
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2025 12:09 AM
1st line is incorrect I think it'll be Glideaggregate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2025 12:44 AM
Hi @vbbfhg please check below link and do modification as per your need
https://www.youtube.com/watch?v=Y4m_yquAMhk
if my answer helps you mark helpful and accept solution