Get Duplicates
Run as a background script
///////////////// FETCH ALL RECORDS //////////////////
var ci = new GlideRecord('cmdb_ci_computer');
ci.query();
////////// CREATE AN OBJECT TO STORE ITEM NAME AND COUNTS////////////////
var cmdb = {};
//////////// ITERATE THROUGH GLIDERECORD OBJECT///////////////
while(ci.next()){
var ci_name = ci.name.toString();
if(cmdb[ci_name]){ // If name is already in object , we will increment its count , else keep it 1
cmdb[ci_name]++;
}
else{
cmdb[ci_name] = 1;
}
}
//////////////// Initialze an array and store all duplicate records////////////////
var ditto = [];
for(var name in cmdb){
if(cmdb[name] > 1){
ditto.push(name);
}
}
/////// ITERATE THROUGH DUPLICATE ARRAY AND PRINT VALUES /////////////////////////////
for(var i=0; i < ditto.length; i++){
var names = ditto[i];
var count = cmdb[names];
gs.print('DUPLICATES OF '+ names +' ---------> '+ count);
}