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-19-2014 03:12 AM
Tony,
If there is any direct way to achieve this ---Grouping on multiple fields --- then i am not aware of it.
For your problem here, can you create 2 Glide Aggregate. I mean like the script that you wrote , use its output in the next GlideAggregate and there you can Group by a different field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 02:51 AM
Hi , I was just wondering if the grouping on multiple fields was achieved , if so , please let us know. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2017 10:52 PM
Hi Tonypod,
Good Day
Hope your script will works fine to find the duplicate records if it exists for the same user. But, I am not sure why are looking to check for email id, however if there is no duplicate records for the same user, the email can't exists duplicate right?
Thanks,
Priyanka R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2016 01:52 AM
Hi ,
I also have the same situation.But when i used the above code i am getting an error"addHaving" is not in use for scoped application.
Can someone help me on this?
Many thanks in advance.
Malaisamy J

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2018 06:08 AM
This script helped us a lot, thanks