We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

GlideAggregate for detecting duplicate records

tonypod
Kilo Explorer

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.

 

  1. getDuplicates();  
  2. function getDuplicates() {  
  3.     var dupRecords = [];  
  4.     var gaDupCheck1 = new GlideAggregate('sys_user');  
  5.     gaDupCheck1.addQuery('active','true');  
  6.     gaDupCheck1.addAggregate('COUNT', 'user_name');  
  7.     gaDupCheck1.groupBy('user_name');  
  8.     gaDupCheck1.addHaving('COUNT', '>', 1);  
  9.     gaDupCheck1.query();  
  10.     while (gaDupCheck1.next()) {  
  11.           dupRecords.push(gaDupCheck1.user_name.toString());  
  12.     }  
  13.     gs.print(dupRecords);  
  14. }
15 REPLIES 15

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.


-Anurag

Hi , I was just wondering if the grouping on multiple fields was achieved , if so , please let us know. Thanks


Not applicable

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


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


This script helped us a lot, thanks