Need a script to find Duplicate CI

Saib1
Tera Guru

Hi,

 

Need to find the duplicate CI which has different Serial Number 

 

Need a Script Include . Can any one help me?

 

 

Saib1_0-1677521430719.png

 

9 REPLIES 9

Sulabh Garg
Mega Sage
Mega Sage

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);

 

 

 

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

@Sulabh Garg 

 

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

 

Saib1_0-1677524766255.png

 

 

 

Bert_c1
Kilo Patron

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.

@Bert_c1 

 

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

 

 

 

Saib1_0-1677559646181.png