How to hide few choices from list view for few users based on the Role

Narasimha10
Tera Contributor

Hi All,

 

I have a requirement where i need to show only 2 state choices InProgress and Pending in List View only to the users based on the logged in user if he has specific role.

 

Can anyone please help me if it is possible to hide few choices of state field to few users from List View in ServiceNow.

1 REPLY 1

Kieran Anson
Kilo Patron

Hi,

You can't remove options from a choice field using an onCellEdit client script. You can either restrict cell editing entirely for the coloumn/table, or use onCellEdit to verify if the value being entered is allowed. The latter isn't a great user-experience and can be frustrating for users.

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
  var saveAndClose = true;

  var RESTRICTED_CHOICES = ['6','7'];

  if(RESTRICTED_CHOICES.includes(newValue) && !g_user.hasRole('role_name')){
	saveAndClose = false;
	alert(getMessage('Operation Not Allowed'));
  }
 callback(saveAndClose); 
}