Making certain fields visible to specific user roles?

Stefan36
Mega Contributor

Hello everyone, 

I'm a newbie to the ServiceNow platform and have a quick question I need help with.
As the title says, I'd like to make certain fields on a catalog item visible only to specific user roles (ex. itil users) but not the rest of the users.

Can someone help me out?

Thanks in advance.

1 ACCEPTED SOLUTION

Gaurav Shirsat
Mega Sage

Hello

You need to write one onLoad Catalog Client Script in Your Catalog Item.

First Type  sc_cat_item.LIST in Application Navigator. your maintain item table will open in new tab.

open your catalog item in new tab by hold ctrl button and click on it.

Now in the bottom.

now here you have 2 concerns that you need to check?

1) is your variable is in Variable Set?

2) is your variable is available normally in Variable section i.e item_option_new table. like below.

first see case 2:-

find_real_file.pngthen you need to write onLoad Catalog Client Script 4th section of above image. Catalog Client Script.

click on new

find_real_file.png

write below script as given,

find_real_file.png 

Case 1:-  if your variables are inside the Variable set then you need to perform this same in variable set.:- 

Go to 2nd tab of variable set. 

Select your variable set and open it. then follow same procedure only difference is you need to add your Variable Set name there.

Please Refer my Article on Role Selection. follow the client side user role section from my Article.

https://community.servicenow.com/community?id=community_article&sys_id=2750d18ddb85a0109e691ea668961...

Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat

View solution in original post

4 REPLIES 4

Paul Curwen
Giga Sage

Hi,  

 

You can do this with Catalog UI Policies. You can find out more about this here:

https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...

Just use this in the UI Policy script which you can find under the Script Tab. Check the 'Run Scripts' field (i.e. make it true) and in the 'Execute if true' field use the following script: 

if (g_user.hasRole('rolename'))
    g_form.setDisplay('variable name',true);
else 
    g_form.setDisplay('variable name',false);
} 

where rolename is the name of the role you want to check e.g. itil and variable name is the name of the variable you want to hide. In this example you can just use the 'Execute if false' field as is as everything is taken care of in the 'Execute if true' script. 

The other thing to be aware of is any potential conflict with Client Scripts which can also be used to set visibility using basically the same code. UI Policies run AFTER Client Scripts and will override any visibility settings done by them. For that reason alone I tend to do all visibility, mandatory, read-only, and clear field requirements in UI Policies rather than Client Scripts.

Please mark as correct/helpful if this helps you

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Is it possible to expand this type of Catalog UI Policy to also require that field be populated, but only when they have a certain role/are in a certain assignment group?

 

The solution I am trying to deliver is a required select box in the portal that asks if the request is being summited due to a walkthrough performed by our facilities unit when the user filling out the form belongs to the facilities assignment group. They don't want to require this for users outside of their assignment group or non ITIL users. 

John Zhang1
Kilo Patron
Kilo Patron

The best approach is to use Load Client Script or ACL.   

The following is a script sample for your reference:

find_real_file.png

Let me know if you need more help.

 

Please mark reply as Helpful/Correct, if applicable. 

Gaurav Shirsat
Mega Sage

Hello

You need to write one onLoad Catalog Client Script in Your Catalog Item.

First Type  sc_cat_item.LIST in Application Navigator. your maintain item table will open in new tab.

open your catalog item in new tab by hold ctrl button and click on it.

Now in the bottom.

now here you have 2 concerns that you need to check?

1) is your variable is in Variable Set?

2) is your variable is available normally in Variable section i.e item_option_new table. like below.

first see case 2:-

find_real_file.pngthen you need to write onLoad Catalog Client Script 4th section of above image. Catalog Client Script.

click on new

find_real_file.png

write below script as given,

find_real_file.png 

Case 1:-  if your variables are inside the Variable set then you need to perform this same in variable set.:- 

Go to 2nd tab of variable set. 

Select your variable set and open it. then follow same procedure only difference is you need to add your Variable Set name there.

Please Refer my Article on Role Selection. follow the client side user role section from my Article.

https://community.servicenow.com/community?id=community_article&sys_id=2750d18ddb85a0109e691ea668961...

Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat