
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 08:18 AM
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.
Thanks
Venkatesh.P
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 12:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 08:39 AM
after line5: add below line,
if(gr.next()){
if(gr.getValue('u_level')>="6"){
answer -=true;
}
else{
answer=false;
}
}
return answer;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 08:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 09:06 AM
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();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 09:33 PM
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