550
Views
5
Comments
Solved
How to set a button from menu invisible depending on User role?
Application Type
Traditional Web

Hey! I am build an app for my mom and she is a teacher. Basically I have a data base with the sutdentes name and their grades. So, the students and my mom do a login and my gets the role "admin" and the students "students". So, if the it is one student, i want the menu to only show 1 button and if it is my mom i want to show 2. How do I do that? Please help :)

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello there Gonçalo,

You can use Check<Role>Role function:


In the menu, you may place some If widgets around the buttons and show them accordingly, using these functions. Or use this function in Visible property of the buttons.

In order to use these functions, you just need to pass an UserId as input parameter. Since you want to check for the logged user, you just need to use something like this:

CheckAdminRole(GetUserId())


Hope that this helps you!


Kind regards,

Rui Barradas

UserImage.jpg
Rio de Imagem Lda

But how do I set the button Invisible?

2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Gonçalo,

Like I said, you can use an If widget to enclose your buttons:

In this example, AdminButton will only be appear if the current logged User has the Admin Role.


Kind regards,

Rui Barradas

2021-02-11 14-19-01
Ivan Leitão

Hi,


Following Rui's logic, I think You could place the button inside an if, which will be based on a boolean variable. This boolean variable should be set to true inside a server action that checks the required role. This action could be initialized on a specific event of the screen, following best practices.


Kind regards,

Ivan Leitão

2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Ivo,

Your response is for Reactive Web Apps, it doesn't apply for Traditional Web Apps (which is the case).

In a Traditional Web App, there are no screen events neither client actions.


Kind regards,

Rui Barradas

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.