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 02:32 PM
I think, you need the setAbortAction business rule on the 'u_accepted_email_domains' table, instead of running it on the main table. Because there is a domain restriction. There could also be a Before Query business rule, which is restricting the visibility of records based on 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-30-2017 01:44 PM
Sorry I wasn't clear, this rule is on the u_accepted_email_domains table and runs before insert or update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 02:34 PM
Hi Karla,
Can you check if you have a onBefore Query business rule on u_accepted_email_domains table and if it is restricting the GlideRecord Query you are using on the insert/update business rule?
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-30-2017 01:39 PM
Okay, let's look at this from a different angle. I want to do something similar on the sys_user table... I want all email addresses to be unique across all domains. I have a before insert and update business rule in the global domain, and I want this rule to search ALL user records, regardless of domain, to insure that there isn't a user who already has the email address. It works right now if a user in Domain A creates a new user record and the email address they enter is already being used in Domain A. But if a user in Domain B creates a user record and enters an email address already used in Domain A, this script doesn't find the matching email address in Domain A and allows the record to be created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 02:43 PM
Hi Karla,
Both Global business rules(Business rules on global table) and script includes are generally domain unaware. So I would suggest that you can call a script include to fetch the results in your before business rule and based on that abort action. I have not tried this on the custom table business rule directly but may be it works. Give it a try.
The script include can have a function say getEmailDomains
getEmailDomains: function(dom) {
var dom = current.u_email_domain;
var rec = new GlideRecord('u_accepted_email_domains');
rec.queryNoDomain();
rec.addQuery('u_email_domain',dom);
rec.query();
return rec.getRowCount() > 0 ; // will return true or false
}