How to hide a field with user roles

tsam
Kilo Explorer

Hi -

How can I hide a field on a form based on the user roles? I have created a role and assigned it to the field on the form but it's not working as expected.

Thanks.

6 REPLIES 6

CapaJC
ServiceNow Employee
ServiceNow Employee

[code]
function onLoad() {
var canSeeIt = g_user.hasRole('admin') || g_user.hasRole('engineering') || g_user.hasRole('field_services');
if (canSeeIt == true)
g_form.setDisplay('cmdb_ci', 'true');
else
g_form.setDisplay('cmdb_ci', 'false');
}


Wow, thank you! works perfectly 😃