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

Thanks, I tried calling a script include but the records that are searched are still limited to those in the same domain.   I believe the issue is that the scripts are running as the current user, who is restricted from seeing data in other domains.



I think I may have been making this hard than it has to be.   If I set the dictionary field Unique to true, that should do the trick, right?


venkatiyer1
Giga Guru

Hi Karla,




Making a field unique could lead to loss of existent values of the field which i would not suggest. Script includes should work for domain access. Can you check the logs to see if there is anything odd happening at that timestamp? If not, a Hi ticket may be required to check it out further.


kchorny
Tera Guru

Just ran across this post again.  Not sure how I fixed this particular issue 🙂 but 

queryNoDomain(); 

bypasses any domain separation visibility issues and queries records in all domains.