
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 08:26 AM
I have a script include that I'm using as a condition for a UI Action. The requirement is that the user's domain must be a child of the Bronze domain, or the child of a child of the Bronze domain in order to see the button.
Here's the script include that I'm calling with the condition new domainConditionUtil().verifyCBPUser(gs.getUserID())
The logs show:
returning: 23e22c9c0fe9830023b222d8b1050e5d
dParent: 23e22c9c0fe9830023b222d8b1050e5d
dPParent: undefined
Where am I going wrong?
var domainConditionUtil = Class.create();
domainConditionUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
verifyCBPUser: function(userID) {
//check to see if the parent domain of the user is the Bronze domain, or if the parent of the custom process domain is the Bronze domain
var u = new GlideRecord('sys_user');
u.get('sys_id',userID);
var uDomain = u.sys_domain;
var dParent = getParentDomain(uDomain);
//dParent = dParent.toString(); //adding this line didn't fix
gs.log('dParent: ' + dParent);
var dPParent = getParentDomain(dParent);
gs.log('dPParent: ' + dPParent);
if (dParent == '21af3de90f7b32000fe1f3f692050e78' || dPParent == '21af3de90f7b32000fe1f3f692050e78')
{
return true;
}
else
{
return false;
}
function getParentDomain(dID)
{
var thisDomain = new GlideRecord('domain');
thisDomain.addQuery('sys_id',dID);
thisDomain.query();
if (thisDomain.next())
{
gs.log('returning: ' + thisDomain.parent);
return thisDomain.parent;
}
}
},
type: 'domainConditionUtil'
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 11:32 AM
The problem was that the user had no visibility to the parent field on the parent domain record. Once I added the intermediate domain to the 'visibility domains' in a group where this user is a member, the script include started working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 08:29 AM
If you are feeling confident, I would suggest a recursive function. I normally use it in situations like that.
Regards
Greg

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 08:43 AM
Nope, not feeling confident at all. Can you tell me how you would do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 08:42 AM
Hi Karla,
There can be two reasons :
- parent of 23e22c9c0fe9830023b222d8b1050e5d doesnt
- the domain is inactive
Here,maybe first you should convert it to toString() and then query with the sys_id
Simpler,avoid second gliderecord use
- var dParent = u.sys_domain.parent.toString();
- var dPParent = u.sys_domain.parent.parent.toString();
if(dParent == '23e22c9c0fe9830023b222d8b1050e5d ' || dPParent == '23e22c9c0fe9830023b222d8b1050e5d '){}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 11:07 AM
The domain exists and is active, so to test it I ran a background script:
var u = new GlideRecord('sys_user');
u.get('sys_id','963d2f6d37d50300ac208ff1b3990e68'); //this is the sys_id of the user that I'm testing as
var dParent = u.sys_domain.parent;
gs.print('dParent: ' + dParent);
var dPParent = u.sys_domain.parent.parent;
gs.print('dPParent: ' + dPParent);
The result of this is:
*** Script: dParent: 23e22c9c0fe9830023b222d8b1050e5d
*** Script: dPParent: 21af3de90f7b32000fe1f3f692050e78
which are the correct values.
So I modified the script include to this. The log is showing dParent as the correct sys_id, but dPParent as blank.
Why would it work in a background script but not in a script include?
verifyCBPUser: function(userID) {
//check to see if the parent domain of the user is the Bronze domain, or if the parent of the custom process domain is the Bronze domain
var u = new GlideRecord('sys_user');
u.get('sys_id',userID);
var dParent = u.sys_domain.parent;
gs.log('dParent: ' + dParent);
var dPParent = u.sys_domain.parent.parent;
gs.log('dPParent: ' + dPParent);
if (dParent == '21af3de90f7b32000fe1f3f692050e78' || dPParent == '21af3de90f7b32000fe1f3f692050e78')
{
return true;
}
else
{
return false;
}
},