How to disable UI action for a specific user role but it should be enable for admin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 12:01 PM
Hi,
I need to disabale a UI action for a custom role with non admins, I have used !gs.hasRole('custom-role') like this,
when I use it , it will disable the UI action , form button even for admin users.
But I don't want it to happen. For All non admin users with custom-role should only this button should be hidden/ disable.
What I guess, for the root cause for this issue is gs.hasRole() is always returns true for admin users.
Please help me I'm stuck with this issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 12:16 PM
Hello
Can you pls check if "admin" user has this custom role, that is why admin user is not able to see this button.
Or you can try below code along with (!gs.hasRole('custom-role') || gs.hasRole('admin'))
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 04:54 PM
this admin user does not have custom role , What I have found is I guess hasRole always true for admin, I guess due to that even though admin user does not have custom role , it is taken as true.
here's my logic,
if(gs.hasRole('custom-role') ){
answer = false;
}
else {
answer = true;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 08:20 PM
Hi,
You have to use it like below:
f(gs.hasRole('custom-role')&& !gs.hasRole('admin') ){
answer = false;
}
else {
answer = true;
}
gs.hasRole('any_role') will always return true for admin, so we have to add additional check for admin like above.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2022 03:57 AM
this is the expected behavior
I want this UI action to be visible only when custom role is added for a particular user , but if even though admin has this role, these UI actions should enable to admin.
here's how I added condition
Actual behavior - even admin doesn't has custom role, admin is not able to see the Request approval button. Please help me to resolve this