- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2018 06:26 PM
Hello Experts,
I want to delete the duplicate records from router interface table, I scripted following code, but not sure, why isnt it working,
Can you help please?
var dup = new GlideAggregate('dscy_router_interface');
dup.addAggregate('COUNT', 'mac_address');
dup.addHaving('COUNT', 'mac_address', '>', '1'); //returns only records having more than one active instance of dupeField (duplicates)
dup.query();
var listOfDupes = []; //build array to push the results into
while (dup.next()) {
listOfDupes.push(dup.getValue('mac_address')); //Push the value of the dupe field to the array
}
var dup1 = new GlideRecord('dscy_router_interface');
dup1.addQuery('sys_id','IN',listofDupes.toString());
dup1.orderByDesc('sys_created_on');
dup1.query();
dup1.next();
while(dup1.next())
dup1.deleteRecord();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2018 07:21 PM
May be you can try with below script:
var dup = new GlideAggregate('dscy_router_interface');
dup.groupBy('mac_address');
dup.query();
while(dup.next()) {
var dup1 = new GlideRecord('dscy_router_interface');
dup1.addQuery('mac_address', dup.mac_address);
dup1.query();
dup1.next();
while(dup1.next())
dup1.deleteRecord();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2018 07:21 PM
May be you can try with below script:
var dup = new GlideAggregate('dscy_router_interface');
dup.groupBy('mac_address');
dup.query();
while(dup.next()) {
var dup1 = new GlideRecord('dscy_router_interface');
dup1.addQuery('mac_address', dup.mac_address);
dup1.query();
dup1.next();
while(dup1.next())
dup1.deleteRecord();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 07:35 AM
Thanks! this worked really well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2018 09:57 PM
Thank you Shishir
I have the same issue and It worked perfectly. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 08:37 AM
Hi Shishir, If I needed to check on 2 fields how would I need to change the code?
Example
John Doe
John Johnson
John Doe
Remove the second John Doe.