How to find if there are any duplicate records in any table of ServiceNow?
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2024 07:27 AM
Hi,
Is there a way to find if there are any duplicate records in ServiceNow table?
Regards
Suman P.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2024 12:33 AM
///////////////// 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