Access restriction to a Catalog item

Venkatesh5
Tera Contributor

Hi All,

I have scenario. where I have to restrict users to view the Catalog items in Serviceportal based on the level(a custom field value from sys_user form) configured to the user. Below is the code and it is not working as expected. I am not able to view the gs.log() content under System log--> All which is written on below code.

Please share your thoughts to figure out the issue.

find_real_file.png

Thanks

Venkatesh.P

1 ACCEPTED SOLUTION

reginabautista
Kilo Sage

Hi Venkatesh,



Try the below solution (I've tested this in my personal dev instance)



var level= gs.getUser().getRecord().getValue('u_level');


var answer = false;


if(level>=6){


answer=true;


}



gs.log(answer);



Also ensure that this User Criteria is assigned in the 'Available for'   in your Catalog item. This is usually not visible on the form so you may need to do Configure->Form Layout then select Available For then save the form.


find_real_file.png




find_real_file.png


View solution in original post

12 REPLIES 12

BALAJI40
Mega Sage

after line5: add below line,


if(gr.next()){


if(gr.getValue('u_level')>="6"){


answer -=true;


}


else{


answer=false;


}


}


return answer;


Thanks Balaji for the response.



As suggested I have modified the code but it does not resolve my issue. However just want to tell you, the return answer; is not working in Entitlement script.


yes, correct show answer variable only.


if(gr.next()){


if(gr.getValue('u_level')>="6"){


answer =true;


}


else{


answer=false;


}


}


answer;


If it not works then do one thing,


call the entire code in the script include and call the script include in entitlement script.


script Include: entilementscript


client callable: true


code:


var entilementscript = Class.create();


entilementscript.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  entitlecode: function(){


  var answer = false;


  var gr = new GlideRecord("sys_user");


  gr.addQuery("sys_id", gs.getUserID());


  gr.query();


  if (gr.next()) {


  if(gr.getValue('u_level')>="6"){


  answer =true;


  }



  }


  return answer;


  },



  type: 'entilementscript'


});



call this in your catalog item:


answer = new entilementscript().entitlecode();


Hi Balaji,



Thanks   a lot for your response but however it is not given the fruitful result. Can you please check if the code which you have sent is working in   your personal instance so that he will help me out to double check from my end.



Thanks Again.... Balaji.




Regards


Venkatesh.P