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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 06:21 AM
It should work. Can you please check if you are in any of Scoped Application or in Global ?
Goto Toggle bar as shown below and see if you are in Scope App or Global, make sure you are in Global Applicatino
Try with below script:
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:44 AM
gs.print(getDuplicates('incident','number'));
function getDuplicates("incident,number) {
var dupRecords = [];
var gaDupCheck = new GlideAggregate("incident);
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[number].toString());
}
return dupRecords;
}
i have tried with this code it shows me an error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 05:48 AM
i got the same error again with copy paste