- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:27 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:35 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:35 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:37 AM
what is val

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:47 AM
I think you make the changes to the Script, Please just copy paste and it get the result.
val is a parameter which i am passing that is nothing but number.
Please run the same script in your Background Script:
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;
}
You have updated the scirpts with below line since i am passing val as parameter and using in the script at multiple places. I would suggest you to not change the script
function getDuplicates("incident,number) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:49 AM
got the same error again with copy paste