Prevent Duplicate User records

Rahul Kathuria
Tera Expert

Hi,

We have so many duplicate user records in ServiceNow. Clean Up process is in Progress. I want to implement a rule which will restrict the admins/interface to create duplicates based on User ID field. Let's say i have a userid "rkathuria" already in the user table, if i try to create a new user id with this name then i should get a pop up or an error message saying " User account with this name already exists in the system" and further action should be aborted.

Any help on this would be appreciated.

Thanks,

Rahul

5 REPLIES 5

Patrick DeCarl1
ServiceNow Employee
ServiceNow Employee

Rahul,



This feature you're looking for is already out of the box if a admin or user who has rights to create a new user account via user form. If you take any user id and create one user record and try to create a second one with the same user id the system will abort insert and display below message.




Screen Shot 2016-04-15 at 12.03.28 PM.png


Patrick - i am in Eureka..i guess it will be out of the box in later releases if that is the case.


It works in eureka. Did you try it?


Harish KM
Kilo Patron
Kilo Patron

Hi Rahul,



Modify as per your requirement. Business Rule (before update,insert)



// Here I have checked for both insert and update to avoid duplicates



function onBefore(current, previous) {


if (current.operation() == "update") {

checkDuplicateUpdate();

} else {

checkDuplicateInsert();
}
}


function checkDuplicateInsert()
{
var dup = new GlideRecord("tablename");
dup.addQuery("u_language", current.u_language);// user field
dup.addQuery("u_active", 'true');
  dup.query();
if (dup.next()) {
  gs.addInfoMessage('Already record exists in the table with same language.Check the existing routing ID ' +dup.u_l1_helpdesk_routing_id);
              current.setAbortAction(true);
}
}


function checkDuplicateUpdate()
{
var dup = new GlideRecord("Tablename");
dup.addQuery("u_language", current.u_language);// userfield
dup.addQuery("u_active", 'true');
  dup.query();
if (dup.next()) {
  //gs.addInfoMessage('count' +dup.getRowCount());
  gs.addInfoMessage('Already record exists in the table with same language .Check the existing routing ID '+dup.u_l1_helpdesk_routing_id);
              current.setAbortAction(true);
}
}


Regards
Harish