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

manikorada
ServiceNow Employee
ServiceNow Employee

Have a script something like:



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"){


answer = true;


}


else{


answer = false;


  }


}


answer;


That makes it available to everyone. It does not limit it to people who's Department -> Business partner is Digital.


I think Mani hit the head on the nail, but also for your reference: https://hi.service-now.com/kb_view.do?sysparm_article=KB0551760


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Anthony,



There are few errors. Please try with the below script.


var gr = new GlideRecord('sys_user');


gr.get(gs.getUserID());


var dept = gr.department.getDisplayValue();


gs.addInfoMessage(dept);


var gr1 = new GlideRecord('cmn_department');


gr1.addQuery('name', 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;


  }


}



NOTE : On line 9 remove .getDisplayValue() if that is not the reference field.



Also on another note if you are on Fuji you can go with the user criteria. More info here.


Migrating to Service Catalog User Criteria - ServiceNow Wiki