How to hide a field with user roles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2012 07:55 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2012 02:10 PM
ACL's are best at allowing people to see the data, edit or otherwise manipulate the data. If you just want it not to show up for people with a given role, you can use a client script to show/hide the field. Below is an example on how to do that;
function onLoad() {
var isAdmin = g_user.hasRole('admin');
//console.log("isAdmin: " + isadmin);
if (isAdmin == true) {
g_form.setDisplay('staff_type', 'true');
} else {
g_form.setDisplay('staff_type', 'false');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 01:16 PM
what if I don't want the logged in user but a person who is selected on the form in the reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2012 02:25 PM
I'm not sure I fully understand your goal, but you could also try a Read ACL on that field with the following script, and make sure the "Admin overrides" field is checked on the ACL:
!gs.hasRole("u_role_you_want_to_deny_access_with");
The users with that role who don't have the "admin" role WON'T be able to see the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2013 02:07 PM
Hello,
How would I modify the below scipt to allow 3 or more roles to view the configuration item on incident tickets?
example roles:
admin
field_services
engineering
function onLoad() {
var isAdmin = g_user.hasRole('admin');
//console.log("isAdmin: " + isadmin);
if (isAdmin == true) {
g_form.setDisplay('cmdb_ci', 'true');
} else {
g_form.setDisplay('cmdb_ci', 'false');
}
}