How do you find duplicate user records in ServiceNow that have the same email address
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2019 06:18 AM
Hi,
We've discovered an issue in Servicenow if a user has more than one ID with the same email address, it stops from receiving emails about requests pending their approval.
So what I'm wanting to do is find a way of searching for all users that have the same email address in more than one user record. I was just wondering how this can be done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 01:35 AM
Hi. How do you run a background script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2019 06:53 AM
Paste this into a background script
var ga = new GlideAggregate('sys_user');
ga.addAggregate('COUNT', 'email');
ga.orderByAggregate('count', 'email');
ga.query();
while(ga.next()) {
gs.info(ga.email + " identicalEmails " + ga.getAggregate('COUNT', 'email'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 01:35 AM
Hi. How do you run a background script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2019 07:11 AM
Please mark as correct if my solution helps fixing your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 03:18 AM
//Iterate through whole records
var gr = new GlideAggregate('sys_user');
gr.addAggregate('COUNT', 'email'); // Email is a Unique key
gr.groupBy('email');
gr.addHaving('COUNT', '>', 1);
gr.query();
while (gr.next())
{
gs.log("Numb of Duplicates: " + gr.getAggregate('COUNT', 'email') + " => " + gr.user_name, 'TEST');
var dup = new GlideRecord('sys_user');
dup.addQuery('sys_id',gr.sys_id); // Get Sysid of record
dup.addActiveQuery();
dup.query();
if(dup.next())
{
var del = new GlideRecord('u_alm_mobile');
del.addQuery('sys_id','!=',dup.sys_id); // Keep Active Record
del.addQuery('email',dup.email); // Search for Duplicate Email Ids Record
del.query();
while(del.next())
{
del.deleteRecord(); // Delete Duplicate Id's Record.
}
}
}
If Possible mark it helpful or Correct.
Thanks,
Aniket