- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2019 07:41 AM
We use an LDAP data source to populate users, groups, and group memberships. We have identified that the sys_user_grmember table has duplicate entries. For example, if user A should belong to group X, there may be more than 1 A/X entry in the sys_user_grmember list, making the group member list appear longer than necessary. This does not happen often. I will investigate the root cause separately. In the meantime, I need to remove the duplicates.
The https://community.servicenow.com/community?id=community_question&sys_id=91864725db1cdbc01dcaf3231f9619d9&view_source=searchResult posting is helpful but I want to find duplicate records in the source table and remove them.
How is an effective method to find those duplicate entries in a ServiceNow table given a set of criteria?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2019 07:52 AM
You can probably use something like this. We were getting users with duplicate email because of multiple sources of records and we used this script to be able to find them.
var userGr = new GlideAggregate('sys_user'); // replace with your table name
userGr.groupBy('email'); // field on which you want to find duplicate
userGr.addHaving('COUNT', '>', 1);
userGr.query();
while(userGr.next()){
gs.print(userGr.email); // adjust field name as per your table
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2019 08:46 AM
Hi Ankur,
You are correct that I need to identify duplicates for a concatenation of multiple fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 10:26 AM
I'm a bit disappointed that the ServiceNow sys_user_grmember table doesn't have a distributed primary key that prevents duplicates from being created. Alternatively, the SOAP or REST service could take over. Additionally, ServiecNow does not support group nesting, which most operating systems do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2022 07:31 AM
Hi Good day! I would just like to ask what is the root cause for this? and did the script works on duplicate entries? did you just use business rule before query for the script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2022 07:38 AM
I don't know what the root cause of the original question would have been. However the script I provider was just something to run in script background so you can find the duplicates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 11:48 AM
Do you have the part that will then remove one of the duplicate entries? I tried to run the following script, but it does nothing (no error, just doesn't remove the duplicates thought it will list the duplicate groups I am a member of.)