How to find if there are any duplicate records in any table of ServiceNow?

Community Alums
Not applicable

Hi,

Is there a way to find if there are any duplicate records in ServiceNow table?

Regards

Suman P.

5 REPLIES 5

GagandeepS48428
Tera Contributor
///////////////// FETCH ALL RECORDS //////////////////
var ci = new GlideRecord('cmdb_ci');
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);
}

 Hi @Community Alums ,

Here is a script , it lets you find duplicate records on cmdb_ci table without using GlideAggregate() , You can take it as  reference and can use your table name and field name , 

Please mark it helpful if it works