Search for duplicate users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:25 AM
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.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:41 AM
Agreed on removing records. I'm only focusing on clearing the value in the Userid field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:45 AM
Whew!
Let me know if you run to problems on that GlideAggregate part.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:52 AM