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

suryanair
Mega Expert

Use before query business rules.Scripting in Business Rules - ServiceNow Wiki


Hi Surya,



Thanks for your response.



Please share me, if you have any sample code. It will very helpful for me.



Regards,
RK


Chuck Tomasi
Tera Patron

Hi RK,



You can restrict or show catalog items using User Criteria. These are flexible to allow you to define groups of people based on role, group, location, and more then determine if you want to allow or deny access to an item based on that group of people. These are far superior to the simple roles we used to have on catalog items in the past.



User Criteria - ServiceNow Wiki


Hi,



I have created a new user criteria and added the role to restrict, but where I need to call this User Criteria in Catalog Item?



Thanks for understanding,


RK