Search for duplicate users

Michael Bachme1
Kilo Guru

We are LDAP integrated. When an employee is a rehire, our HR department creates a new user instead of using the old. When this happens, we end up with two user accounts, one being inactive. The user is not able to get into ServiceNow as a result.

I'd like to create a scheduled job that runs a script against the sys_user table that does the following:

1. Checks for duplicate User IDs

2. If duplicates exist clear the User ID of the inactive account

Any guidance on how to write this script is appreciated.

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Michael,



The key to making this work is GlideAggregate. It's similar in nature to GlideRecord, but accesses native database methods to count records. Several related examples here:



GlideAggregate - ServiceNow Wiki



FWIW, I highly recommend against removing records as it can cause "dangling references". There may be lots of records that try to reference the record you just deleted and now those references are broken.


Agreed on removing records. I'm only focusing on clearing the value in the Userid field.


Whew!



Let me know if you run to problems on that GlideAggregate part.


Hi Michael,



Please refer below thread for more info.


Find duplicate user email (or anything else)