Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help with an Entitlement Script

aessling
Mega Expert

I am trying to write an Entitlement Script that will allow users with a specific Business Partner to access a Record Producer Item in our Catalog. The problem is that the Business Partner field is on the Department table and I don't appear to be able to double dot walk in a Entitlement Script. Below is the Script that I have been trying to get to work but have not had any success. This is the first time I have tried to use an entitlement script and I don't really know what I am doing. Any help would be appreciated.

var gr = new GlideRecord('sys_user');

gr.get(gs.getUserID());

var dept = gr.department.getDisplayValue();

var gr1 = new GlideRecord("cmn_department");

gr1.addQuery('id', '=', dept);

while(gr1.next()) {

  var bp = gr1.u_business_partner.getDisplayValue();

if (bp == "Digital"){

  true;

}

else{

false;

  }

}

1 ACCEPTED SOLUTION

That almost got me there but I had to make a couple changes to get it to work. Thank you everyone for your help. Here is what finally worked:



var gr = new GlideRecord('sys_user');  


gr.get(gs.getUserID());  


var dept = gr.department;  


//gs.addInfoMessage(dept);  


var gr1 = new GlideRecord('cmn_department');  


gr1.addQuery('sys_id', dept);  


gr1.query();  


while(gr1.next()) {  


var bp = gr1.u_business_partner.getDisplayValue(); //remove .getDisplayValue() if this field is not a reference field  


if (bp == "Digital"){  


answer = true;  


}  


else{  


answer = false;  


  }  


}  


View solution in original post

7 REPLIES 7

That almost got me there but I had to make a couple changes to get it to work. Thank you everyone for your help. Here is what finally worked:



var gr = new GlideRecord('sys_user');  


gr.get(gs.getUserID());  


var dept = gr.department;  


//gs.addInfoMessage(dept);  


var gr1 = new GlideRecord('cmn_department');  


gr1.addQuery('sys_id', dept);  


gr1.query();  


while(gr1.next()) {  


var bp = gr1.u_business_partner.getDisplayValue(); //remove .getDisplayValue() if this field is not a reference field  


if (bp == "Digital"){  


answer = true;  


}  


else{  


answer = false;  


  }  


}  


Hi Anthony,



If you use


var dept = gr.department.getDisplayValue() then the code I provided should have work.



BDW Glad your issue is resolved now.


Hi Pradeep,



I'm facing a an issue with my entitlement script.I am trying to hide a catalog item based on the location/country of the user. I am trying the below script but nothing is working i believe.


Can you help me out here how to hide my catalog item for specific users. This is my first attempt at an entitlement script.



var country = gs.getUser().getCountry();


if(country=='IN'){


answer= true;


}


else


{


answer = false;


}