How to hide catalog item base on role?

firemoon
Mega Expert

Hi,

I want to hide a catalog item based on role.

For

role 1 : All Catalog item should be enable

role 2: Last 2 catalog items only enable.

Please help me to fix this.

find_real_file.png

Regards,
RK

1 ACCEPTED SOLUTION

Ajaykumar1
Tera Guru

Hi,

1. Create a new User Criteria > Give it a meaningful name > Check "Advance",in script section add following code :

if(!user.hasRole("role_who_can_view_item"))
{
condition =false;//set visiility to false if user don't have "role_who_can_view_item" role
}

OR

Configure > Related Lists > Pull Not Available for / Not available for Group and configure it.

Also, double check whether the group from whom you are hiding the items have the correct role.

 Refer : Catalog item visibility in ServiceNow

Regards,
Ajay

View solution in original post

18 REPLIES 18

Ensure you have the related list "Available for" and "Not available for" on your catalog item.



find_real_file.png


Add the defined user criteria to the "Available for" list.


Hi Chuck!
  When I go to test a user criteria on a catalog item for a specific user, I noticed that the catalog item is still visible for them and they are just brought to a page that displays 'Not authorized'.   I was under the impression it would remove the item completely from the catalog where they can even see it unless they are a part of a group/role.   Does User Criteria not include this type of capability?   If not, is there an alternative way of achieving this?   Any help is appreciated.



Thanks,


Fred


Hi Fred,



Can you include some addition details? Steps you took and screenshots are helpful. I'm not quite wrapping my head around the issue.


Hi Chuck,


No problem.   Here is a screenshot of the user criteria I created for a specific group:User Criteria.png


Here is the "available for' related list I added on the catalog item I am trying to hide.


Available For.png


When I login as a user who is not currently is this assignment group defined in the user criteria, they are still able to view the catalog item.   'Apple MacBook Pro'.    


Mac.png


Instead of hiding the item itself they can are still able to click on it, but are brought to another page where the 'not authorized' is displayed.


not suthorized.png



Thanks,
Fred


Well that's not right! I don't have an instant answer for you. It appears everything is configured properly. You might need to take this one to support. Let us know what they say.



HI Service Portal - ServiceNow


Contact Support | ServiceNow