Domain scope in script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 01:33 PM
I have a custom table that will be used in all domains, and I need one of the fields to be unique across all domains. But the before business rule I wrote to restrict entering a value that has already been used is only searching for duplicates in the user's domain, rather than in all domains. How can I expand the domain scope in the script so that it searches for duplicates in all domains? The business rule is in 'global'.
(function executeRule(current, previous /*null when async*/) {
var dom = current.u_email_domain;
var rec = new GlideRecord('u_accepted_email_domains');
rec.addQuery('u_email_domain',dom);
rec.query();
if (rec.getRowCount() > 0)
{
current.setAbortAction(true);
gs.addErrorMessage('Email domain is already defined and cannot be used again.');
}
})(current, previous);
Thanks for any help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 01:44 PM
Hi Karla,
I guess your user domain table is 'u_accepted_email_domains'. Do you have a parent table, which stores all the domains? You can do a query on that parent table instead of just querying u_accepted_email_domains.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 02:02 PM
Accepted Email Domains is a single table with a sys_domain column. Users can only see records in their domain. But the business rule is only looking at records in the user's domain, and I need it to look at all records to determine if a user is attempting to add a duplicate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 02:26 PM
Hi karla,
Since u_email_domain is currently holding the domain value, wouldnt be enough if omit rec.addQuery('u_email_domain',dom);
(function executeRule(current, previous /*null when async*/) {
var dom = current.u_email_domain;
var rec = new GlideRecord('u_accepted_email_domains');
rec.query();
if (rec.getRowCount() > 0)
{
current.setAbortAction(true);
gs.addErrorMessage('Email domain is already defined and cannot be used again.');
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:28 PM
u_email_domain is holding an email domain value, such as gmail.com, yahoo.com, etc. not the value of one of our SNow domains.