Get parent of parent in script include

kchorny
Tera Guru

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'

});

1 ACCEPTED SOLUTION

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.


View solution in original post

5 REPLIES 5

Greg42
Mega Guru

If you are feeling confident, I would suggest a recursive function. I normally use it in situations like that.




Regards



Greg


Nope, not feeling confident at all.   Can you tell me how you would do this?


Sharique Azim
Mega Sage

Hi Karla,



There can be two reasons :


  1. parent of 23e22c9c0fe9830023b222d8b1050e5d doesnt
  2. 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


  1. var dParent = u.sys_domain.parent.toString();  
  2. var dPParent = u.sys_domain.parent.parent.toString();

if(dParent == '23e22c9c0fe9830023b222d8b1050e5d '   || dPParent == '23e22c9c0fe9830023b222d8b1050e5d '){}


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;


}


},