Need to Limit Users to View A Specific Location

I am creating an inventory app. There are "Property Managers" at specific locations who need to see only the data for their location. I am also limiting them to see certain columns based on their user role. That was pretty easy.

Where I'm having trouble is writing the security filter expression that looks in the "User Manager" table and finds the Role that is "Property Manager" then finds the "Location" that displays only the matching records from the "Inventory table" at that "Location". "Admin" users should be able to see all records. Can you please help? I've searched Google and Youtube. I am new to Appsheet and coding. 

0 3 125
3 REPLIES 3

Aurelien
Google Developer Expert
Google Developer Expert

@DGillcpa wrote:

Where I'm having trouble is writing the security filter expression that looks in the "User Manager" table and finds the Role that is "Property Manager" then finds the "Location" that displays only the matching records from the "Inventory table" at that "Location". "Admin" users should be able to see all records. Can you please help? I've searched Google and Youtube. I am new to Appsheet and coding. 


Hi @DGillcpa 

You may want to use this expression in the security filter of the table "Inventory table":

OR(
  USERROLE()="Admin",
  AND(
    LOOKUP(USEREMAIL(),"User Manager","email","role")="Property Manager",
    LOOKUP(USEREMAIL(),"User Manager","email","Location")="Location"
  )
)

For reference:

LOOKUP() - AppSheet Help

Limit users to their own data - AppSheet Help

OR() - AppSheet Help

AND() - AppSheet Help

 

 

Thank you, I used your suggestion but it still shows records for every
location in the preview. I decided to create slices for each location and
limit the view to only users with that location in the Display area. That
appears to be working.

I appreciate the help. I have a lot to learn.


@DGillcpa wrote:

it still shows records for every
location in the preview


In the preview you are always considered with USERROLE="Admin" no matter the setting you use, hence this behavior. I admit this is quite confusing.

Can you give it a try out of the preview pane, and with another account than the app owner's account?

Top Labels in this Space