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

Hi,

I see, in this case gs.hasRole() will not work.

Please use below logic:

(gs.getUser().getRoles().indexOf('custom_Role')>-1)   ---> Return true if loggedIn user having custom_role else return false

 

User it in your UI Action condition accordingly.

 

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

Kartik Sethi
Tera Guru
Tera Guru

Hi @SSA 

 

Please update the condition as provided below:

(!(gs.getUser().getRoles().indexOf('custom_role') >= 0) || gs.getUser().getRoles().indexOf('admin') >= 0)

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik