Finding Duplicate Records in CMDB

Mujahid Sharief
Tera Contributor

Hi All, I have implemented script to find out the duplicate records with the help of serial number in background scripts. Please check the below script:

gatherDupes();

function gatherDupes() {
var gr = new GlideAggregate('cmdb_ci_computer');
gr.addAggregate('COUNT', 'serial_number');
gr.groupBy('serial_number');
gr.addHaving('COUNT', '>', 1);
gr.query();

var dupSerialNumber = [];
gs.log("The following " + gr.getRowCount() + " CIs has duplicates based on serial number field...");
while (gr.next()) {
gs.log("Duplicates: " + gr.getAggregate('COUNT', 'serial_number') + " => " + gr.serial_number);
}
}

Now that i was able to find the duplicate records. This is how it looks: after running in background

*** Script: The following 4 CIs has duplicates based on serial number field...
*** Script: Duplicates: 106 =>
*** Script: Duplicates: 2 => 56WHL71
*** Script: Duplicates: 2 => AEX5635Z0001AC
*** Script: Duplicates: 16 => L3BB911

If serial number 56WHL71 has 2 Duplicates . Now the requirement is what is the discovery source of these both?

Now there is a Integration with BMC discovery. so, one discovery source should be BMC DIscovery and other should be empty or unknown as the record is created manually.

What should i add in the above script so that i get the discovery source of these 2 serial number.

It should print like 1. serial number (56WHL71) is with discovery source BMC discovery and

2. serial number (56WHL71) is with discovery source unknown or empty or system.

please advise.

1 REPLY 1

Yousaf
Giga Sage

Hi,

Please refer to this link and see if something like this will work in your scenerio

GlideAggregate: grouping by multiple columns

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***