Hide choice value on list view?

kris29
Tera Contributor

Hi,

How to hide a choice value (Linux) on the list view for a user with non admin access ?

On form I used client script onLoad but it's not working on onCellEdit.

var adminUser= g_user.hasRole('admin');

if (!adminUser){
     g_form.removeOption('operation_system', 'Linux');
}
1 ACCEPTED SOLUTION

Shakeel Shaik
Giga Sage
Giga Sage

Hi kris,

 

Create OnCellEdit Client Script:

select field - operation_system

script:

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

	//In Place of "10" add your Linux value

	
    if ((newValue == '10') && (g_user.hasRole('admin'))) {
        saveAndClose = true;

    } else {
        alert('Only admin can select this choice');
        saveAndClose = false;
    }

    callback(saveAndClose);
}

If my above response is helpful, then Please mark as Correct Answer/Helpful.

Please check and let us know.

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

View solution in original post

8 REPLIES 8

DrewW
Mega Sage
Mega Sage

Check out the docs here

https://docs.servicenow.com/bundle/paris-application-development/page/script/client-scripts/concept/client-scripts.html

Basically, if memory serves its not possible, you have to use an onCellEdit client script validate that they are allowed to pick it or not and if not don't do the update.

If only an admin can use it you may want to consider a UI action that an admin can use to set the value for the field to "Linux" and then just remove it from the dropdown.

 

Baala T
Mega Guru

Hi Kris,

Check this link https://community.servicenow.com/community?id=community_question&sys_id=b8d08f65db98dbc01dcaf3231f96194c

 

Regards,
Bala T

kris29
Tera Contributor

I need to hide/restrict choice value on lit view, not form view

If you look thru that one you will find a link to this
https://community.servicenow.com/community?id=community_question&sys_id=5f55c7addbd8dbc01dcaf3231f96193f

which uses an ACL which should work for your case.