The CreatorCon Call for Content is officially open! Get started here.

I want to hide a button (UI Action) from users with a certain role

ewilks
Giga Expert

In the condition of the UI Action, I currently have the following code: current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList()

 

I would like to keep anyone who has the role of auditor from seeing this UI Action (button), so I added: && !gs.hasRole('auditor')

 

The entirety of the condition is now:   current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList() && !gs.hasRole('auditor')

 

I assumed that this would mean, that for a user to see this, they would have to not have the role of auditor.   But when I impersonate an auditor, I still see the button.

 

What am I doing wrong?

16 REPLIES 16

m_servicenow
Kilo Contributor

Eric,


You can use below script in condition. Just paste below script:



(current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList()) && !gs.hasRole('auditor')



Let me know if still you getting issues.



I believe now you can do what you want exaclty


I tried that, but it hid the button (UI Action) only from the admin, so I tried this:


(current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList()) && (gs.hasRole('admin') || !gs.hasRole('auditor'))



Now the admin can see the button, just like every other user, including those with auditor role.


Hi Eric,



Were you able to find a resolution to this?   I"m running into the same issue where the !gs.hasRole("role") does not work.


Ken,


Yes, I did.   Here is what happened in a nutshell...


The original was like this:


current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList()




I updated it to this which didn't work:


current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList() && !gs.hasRole('auditor')



Ultimately, used this and it worked


current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList() && (!gs.hasRole('auditor') || gs.hasRole('admin'))



Notice that I added parenthesis to the last two qualifiers so that the (user is not auditor OR is admin).   I hope it helps.


vaibhavdesai
Kilo Expert

Hello,



I am running into same problem "!gs.hasRole('asset_viewer')" hides button from every single user in service-now. So i tried solution given above "(!gs.hasRole('asset_viewer') || gs.hasRole('admin'))".


Now in this case i am able to hide button from asset_viewer and admin is able to see it.But, what about other users? how i can show this button to them.



Thanks for the help in advance.