Need a script to find Duplicate CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 10:11 AM
Hi,
Need to find the duplicate CI which has different Serial Number
Need a Script Include . Can any one help me?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 10:36 AM
Hi Saib,
Please check the below Fix script/Background script, It should work for you,
var arraylist = [];
var dup = new GlideAggregate('cmdb_ci');
dup.addAggregate('COUNT','serial_number');
dup.addHaving('COUNT','>', '1');
dup.groupBy('serial_number');
dup.query();
while(dup.next()){
arraylist.push(dup.getValue('serial_number'));
}
gs.print('Duplicate CIs' + arraylist);
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 10:57 AM - edited 02-27-2023 11:06 AM
I need to take the Count from the script not the array list of CI/Serial Number
It should return the count as 3 because it has same ci which has different Serial number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 12:12 PM
Adding a bit more logic to the script from Suhlab
var arraylist = [];
var dup = new GlideAggregate('cmdb_ci');
dup.addAggregate('COUNT','serial_number');
dup.addHaving('COUNT','>', '1');
dup.groupBy('serial_number');
dup.query();
while(dup.next()){
arraylist.push(dup.getValue('serial_number'));
}
gs.print('Duplicate CIs' + arraylist);
for (i=0; i < arraylist.length; i++) {
var dupci = new GlideRecord('cmdb_ci');
dupci.addQuery('serial_number', arraylist[i]);
dupci.query();
gs.info("CI SN: " + arraylist[i] + " has " + dupci.getRowCount() + " records.");
}
Results in:
*** Script: Duplicate CIs,56WHL71,AEX5635Z0001AC,L3BB911
*** Script: CI SN: has 2036 records.
*** Script: CI SN: 56WHL71 has 2 records.
*** Script: CI SN: AEX5635Z0001AC has 2 records.
*** Script: CI SN: L3BB911 has 15 records.
in my PDI, note there are 2,036 records with no value for serial_number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 08:48 PM
here in this table alm_hardware , i have only 3 records
when i tried your code it is not giving the count as 3
Results should show 3