How to disable a button if current user doesn't have a role, specified in other table

Hi! I got two tables.

First one contains a button that I need conditionally disable.
Second one contains list of users and a Select list with user roles.

Question: how to disable a button if current user doesn’t have specified role in that second DB?

1 Like

Hi @Dmitry_Kuchev and Welcome to the Community :partying_face: !

Maybe something like this would work as a Disable if formula in your button :

Users.Filter(People = User()).First().Roles = [Role 3]

In my very quick test, this disables the button if the Current user (User()) was assigned the [Role 3]

Here’s a screenshot of the doc I used to test this, which might be similar to yours :blush:

And what the Disable if formula

Users.Filter(People = User()).First().Roles = [Role 3]

… does is : it takes my table Users and look for (Filter()) the row where the CurrentValue.People is equal to the Current user (User()). (and because Filter() always returns a list of rows, .First() is there to actually extract the row from the list).
Then, from that row, we get the corresponding role and check if it’s equal to the role for which the button should be disabled :blush: .

Another way to do this could be to use MaxBy()

Users.MaxBy(People = User()).Roles = [Role 1]

Something else that might work, if you stored your various roles in a table and use a lookup field to select the role for the people within your Users table, could be to add a checkbox to the Roles table to indicate which roles should disable the button and which shouldn’t :blush:
(Here I chose Checked should disable and Unchecked shouldn’t)

In your Users Table, you can then gather that value (by adding a related column from the lookup field) and use a Disable if formula in your button such as

Users.Filter(People = User()).First().Disable

Which follows the same principle as before, but instead of looking for a specific role, it will check the value of the Disable checkbox already tied to a specific role :blush:

Depending on your actual setup you might need to adapt the Disable if formulas I shared here :blush: , but I hope this will help you a little :innocent:.

1 Like

Fantastic! Thanks! It totally worked :slight_smile:

No problem @Dmitry_Kuchev :grin: !
I’m very glad to know this helped you moving forward :raised_hands: !

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.