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

Mihir Mohanta
Kilo Sage

You need to use user criteria for this.


Please go through below thread.It might help you.



User Criteria not working



Thanks,


Mihir


Rshear
Kilo Expert

If your on Eureka..probably the best way until you upgrade is to add the 'entitlement script' field to the catalog item itself (under maintain items)..then write a script that checks if logged in user has x role..if they have role x display i.e. answer = true. if they dont have role x then dont display i.e. answer = false.



Should be simple and easy to do.


Priyanshu
Giga Expert

Hello Rshear,

 

I need to fetch the list of catalog item on the basis of user ( how many catalog item user x can access ). I need an API for the same can you guide me how to achieve this.

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