Choice list to show depending upon Roles

Vignesh21
Kilo Guru

HI,

Use case: We have a choice list which has 5 values and i have given on load client script to remove option from the choice list depending upon roles. This is working fine on the form. But on the list view i am able to see all the choice values.

Is there a way we could hide the values on list view depending upon roles.

-Vignesh

1 ACCEPTED SOLUTION

Henrik Jutterst
Tera Guru

I would suggest a new Client Script that runs onLoad.

 

function onLoad() {
	//who to display it for - admin
	var isAdmin = g_user.hasRole('admin');

	if (!isAdmin){
		g_form.removeOption('contact_type', 'integration');
	}
}

View solution in original post

19 REPLIES 19

Can you share with us the code you used in the onCellEdit client script?



Thank you


Chuck I think that would probably would not solve the issue as the cell edit client script is not called on load but only when a field gets changed. By using cell edit we can use the required logic and terminate the transaction. But then on the list view I found no option to hide the choices.



Please through your valuable insights.


If you cannot change the functionality via onCellEdit client script then the only thing left to do is create an ACL to prevent cell editing and force the user to make changes to that field via the form. Look for the operation in the ACL "list_edit".



Docs: Access control rules


Docs: Contextual security  


Security Best Practices - ServiceNow Wiki


Hi Chuck,


The scripts are as below.


-----------------------------------------------------------------------------------------------------


function onCellEdit(sysIDs, table, oldValues, newValue, callback) {


  var saveAndClose = true;


//Type appropriate comment here, and begin script below


if (g_user.hasRoleExactly('SABC') ) {


g_form.removeOption('install_status', 1);


g_form.removeOption('install_status', 3);


g_form.removeOption('install_status', 7);


g_form.removeOption('install_status', 8);


g_form.removeOption('install_status', 9);


g_form.removeOption('install_status', 10);


}


callback(saveAndClose);


}



--------------------------------------------------------------------------------------------------------



Please let me know if anything wrong from the script.


According to the documentation, g_form is not supported in onCellEdit scripts. Sorry. It looks like you're not going to be able to modify the choices as displayed in a list edit from a script.