- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 11:55 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2017 11:45 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2017 11:45 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 08:36 AM
Good Morning Lasse,
It looks like this is going to work!
Thank you so much…your help is much appreciated!
Eddie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 10:08 PM
Hi Eddie,
You are welcome. Please remember to mark the correct answer as "Correct". This way others can easily find the correct answer and does not have to scroll through our conversation.
Also it gives me points 🙂
Kind regards
Lasse
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 08:25 AM
Will do…! I do have another question though lol! Would it be a difficult to have a "If" query to where unless it is a 3 digit phone # (could span across multiple switches), everything else regardless of the switch or not does not allow dupes. In other words, when a 3 digit phone # is entered, the current code looks at switch and #. Moreover, anything above 3 digits entered just looks at the phone# regardless of switch and flags duplicates.
Thanks!
Eddie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 09:57 PM
Hi Eddie,
Yes, sure. You can always add an if statement and only include the switch in case the number is longer than 3 characters.
I added this twice in below example so that you can also have different errors depending on if the error is with the phone and switch or just the phone:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_phone_numbers');
gr.addQuery('name',current.name);
if(current.name.toString().length > 3)
gr.addQuery('u_switch',current.u_switch);
gr.query();
if(gr.next()) {
if(current.name.toString().length > 3)
gs.addErrorMessage("The phone number on the selected switch is already in use");
else
gs.addErrorMessage("The phone number is already in use");
current.setAbortAction(true);
}
})(current, previous);
Have a nice day!
/Lasse