- 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-11-2017 11:58 AM
You can do this with a before business rule on insert and update.
Check the advanced checkbox and put in a script that checks if the # already exists. If that is the case add:
current.setAbortAction(true);
And the record will not be saved.
Also add:
current.addErrorMessage("The phone number is already in use");
To inform the user of the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 01:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 12:11 AM
Hi Eddie,
I do not know the field names, so you may need to change "u_number" to the fieldname that you used, but here is a script that should do the trick:
var gr = New GlideRecord('u_phone_numbers');
gr.addQuery('u_number',current.u_number);
gr.query();
if(gr.next()) {
current.setAbortAction(true);
current.addErrorMessage("The phone number is already in use");
}
Here is explanation:
In the first line you create a new GlideRecord object.
In the second you filter saying that you want the record with the number, that is entered on the current record which you are about the create.
The third line runs the query on you database.
The if statement checks if there are any results. The idea is that if there is a result, then there is already a record with the number.
In line five the abort is called making sure that nothing is saved to the database.
On the sixth line you add the error message which will be visible on top of the form.
You can also place the error next to the "u_number" field. like so:
current.u_number.setError("The phone number is already in use");
Just place the line under line 5.
I hope this helps!
/Lasse
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 12:12 PM