GlideAggregate for detecting duplicate records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014 08:41 AM
I am trying to detect duplicates across multiple columns using GlideAggregate, but cannot seem to figure it out. Is it even possible? Is there a better way? Here is a snippet for getting unique records when determining uniqueness from single column. I need to do this by looking at two columns.
- getDuplicates();
- function getDuplicates() {
- var dupRecords = [];
- var gaDupCheck1 = new GlideAggregate('sys_user');
- gaDupCheck1.addQuery('active','true');
- gaDupCheck1.addAggregate('COUNT', 'user_name');
- gaDupCheck1.groupBy('user_name');
- gaDupCheck1.addHaving('COUNT', '>', 1);
- gaDupCheck1.query();
- while (gaDupCheck1.next()) {
- dupRecords.push(gaDupCheck1.user_name.toString());
- }
- gs.print(dupRecords);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014 08:55 AM
Hi Tony,
I dont see a problem in the script, can you just tell me where are you running this code? (script include, job, BR etc...). As gs.pring will work on background script.
So try 2 things to cross check your data and query.
Run exactly this code in a background script
- var dupRecords = [];
- var gaDupCheck1 = new GlideAggregate('sys_user');
- gaDupCheck1.addQuery('active','true');
- gaDupCheck1.addAggregate('COUNT', 'user_name');
- gaDupCheck1.groupBy('user_name');
- gaDupCheck1.addHaving('COUNT', '>', 1);
- gaDupCheck1.query();
- while (gaDupCheck1.next()) {
- dupRecords.push(gaDupCheck1.user_name.toString());
- }
- gs.print(dupRecords);
to Verify the result,
go to the user table and group by user name(User Id) and find duplicates, if any.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014 08:58 AM
my suggestion might seem bit lame but give it a try...
add ur script to a script include and call that script in the background script...
try printing the return value from the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014 09:10 AM
The script works for a single field (user_name). I'd like to have it work across two fields: user_name, and email. I'm not sure how to modify the script to make that work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2014 01:37 PM
I'd also be interested in this, had a need for it but couldn't figure it out.