Preventing Duplicate CIs

eddiemorales
Tera Contributor

We have users that are constantly adding New CIs/Phone Numbers and having an issue with duplicate phone #s being added because those are simply not being checked consistenly to see if it already exists. What is the best way to prevent this creation of duplicate phone#s? Business rule, etc? We are looking more in the lines of having a flag or something where once the # is saved, it prompts that "this # already exists" and denies the creation of the new #.

Thanks!

1 ACCEPTED SOLUTION

Hi Eddie,



Sorry, it is supposed to be gs.addErrorMessage() and not current.addErrorMessage().



Here is the complete script:


(function executeRule(current, previous /*null when async*/) {


  var gr = new GlideRecord('u_phone_numbers');


  gr.addQuery('name',current.name);


  gr.addQuery('u_switch',current.u_switch);


  gr.query();


  if(gr.next()) {


      gs.addErrorMessage("The phone number on the selected switch is already in use");


      current.setAbortAction(true);


  }


})(current, previous);



I hope this gets you what you need.



/Lasse


View solution in original post

16 REPLIES 16

bernyalvarado
Mega Sage

Hi Eddie,



I'll suggest two options:


a) you use an insert onBefore Business Rule where you first check if the cell phone number already exists, if not, abort the action and display a message to the user


b) make the phone number field a field with unique values.



Thanks,


Berny


Dave Smith1
ServiceNow Employee
ServiceNow Employee

Is the phone number a reference field?



If it's not related to anything, consider making the field unique - this will prevent duplicates being added.