The CreatorCon Call for Content is officially open! Get started here.

Domain scope in script

kchorny
Tera Guru

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.

12 REPLIES 12

SanjivMeher
Kilo Patron
Kilo Patron

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.

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.


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);


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.