Find Duplicate Records
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 12:15 PM
Hi,
In my user table, I'm seeing multiple records with duplicated. Per existing info, the following fields is going to help to identify the duplicate records. 1. Name, 2. sys_id 3.email.
Can you help the script with the help of same Name, Same Email, Different sys_id and Active is True to find the duplicate records. Per understanding these are the key factor to identify the duplicate records in sys_user table.
I tested with below and helping based on email address.
var gaDupCheck1 = new GlideAggregate('sys_user');
gaDupCheck1.addQuery('active','true');
gaDupCheck1.addAggregate('COUNT', 'email');
gaDupCheck1.groupBy('email');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
gs.print(gaDupCheck1.email);
}
Regards,
LS
Labels:
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 01:13 PM
Hi
The code you wrote also works, what is the issue you are facing?
You can also try below logic too
var gaDupCheck1 = new GlideAggregate('sys_user');
gaDupCheck1.addQuery('active','true');
gaDupCheck1.addAggregate('COUNT');
gaDupCheck1.groupBy('email');
gaDupCheck1.groupBy('name');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
gs.print(gaDupCheck1.email);
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP