Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Find Duplicate record of incident

ABC6
Tera Contributor

Hi All,

i need to get the Duplicate incident record which has been created accidently , i need to find out those record among 6lakh record for this purpose i have run the background script which did not help me to expedite the issue.

 var count = new GlideAggregate('incident');
count.addAggregate('COUNT','number');
count.query();
while(count.next()){
var category = count.number;
var categoryCount = count.getAggregate('COUNT','number');
gs.print("there are currently "+ categoryCount +" incidents with a category of "+ category);}
}

Please suggest me

1 ACCEPTED SOLUTION

AbdulAzeez
Mega Guru

You can run below Background script, assuming You need to find Duplicate Incident Numbers

 

 

 

gs.print(getDuplicates('incident','number')); // Assuming you have duplicate Incident Numbers
function getDuplicates(tablename,val) {
var dupRecords = [];
var gaDupCheck = new GlideAggregate(tablename);
gaDupCheck.addQuery('active','true');
gaDupCheck.addAggregate('COUNT',val);
gaDupCheck.addNotNullQuery(val);
gaDupCheck.groupBy(val);
gaDupCheck.addHaving('COUNT', '>', 1);
gaDupCheck.query();
while (gaDupCheck.next()) {
dupRecords.push(gaDupCheck[val].toString());
}
return dupRecords;
}

 

 Please Hit Helpful / correct based on the impact,

Abdul Azeez

View solution in original post

10 REPLIES 10

Hi,

update script as below and it should work

gs.print(getDuplicates('incident','number'));
function getDuplicates(incident,number) {
var dupRecords = [];
var gaDupCheck = new GlideAggregate(incident);
gaDupCheck.addQuery('active','true');
gaDupCheck.addAggregate('COUNT',number);
gaDupCheck.addNotNullQuery(number);
gaDupCheck.groupBy(number);
gaDupCheck.addHaving('COUNT', '>', 1);
gaDupCheck.query();
while (gaDupCheck.next()) {
dupRecords.push(gaDupCheck[number].toString());
}
return dupRecords;
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader