Restriction to Choice list for role

snowuser111
Kilo Guru

Hi Experts,

I want to restrict the visibility/access to two or three choices in Drop down for Incident. Only certain users with particular role can access the choices/ edit them.

What will be approach please suggest.

Thanks

3 REPLIES 3

Raju Koyagura
Tera Guru

Get the logged in user roles, if any of the role in your list to hide some choice values use removeOption(fieldName, choiceValue) method.



Methods to get the user roles: GlideUser (g user) - ServiceNow Wiki


Methods to add/remove choice values: GlideForm (g form) - ServiceNow Wiki


Julian Hoch
ServiceNow Employee
ServiceNow Employee

Check the client Script "(BP) Hide Choice - Closed" on the incident form. That does exactly what you are looking for.


Henrik Jutterst
Tera Guru

Sure. This example works fine.

Create a new Client Script that runs onLoad

This script hides the (custom) value integration from contact_type field.

function onLoad() {
	//who to display it for - admin
	var isAdmin = g_user.hasRole('admin');
	
	//set up conditions to hide
	if (!isAdmin){
		g_form.removeOption('contact_type', 'integration');
	}
}