- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 07:17 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2019 04:06 AM
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');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 07:50 AM
Can you share with us the code you used in the onCellEdit client script?
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 07:54 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 07:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 08:17 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 08:27 AM
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.