How to disable UI action for a specific user role but it should be enable for admin

SSA1
Giga Expert

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.

6 REPLIES 6

Sulabh Garg
Mega Sage
Mega Sage

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

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

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;
}

 

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

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@Anil Lande This didn't work. I want to apply this for OOB UI action,

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

 

find_real_file.png

 

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