10
Views
2
Comments
Solved
How to hide buttons based on role..?

if an HR Employee login into the application then add the employee button has to be displayed.


 if an employee login into the application then the add new employee button has to be hidden.

Rank: #242
Solution

Hi Anil,

As per my understanding, you want to show the button based on the role of HR and Employee.

Create a server action for the role check of HR, Inside the server action check the logged in user is having the HR role access by checkHREmployee(userid :) and return its Boolean value as the output of the server action. Based on the Boolean value show and hide the button, if the value is true then show the button or hide the button.

Hope this will helps you, in resolving the issue.


Regards,

Koushik  

Rank: #67

Hi Anil,


As you are working on Reactive, you won't be able to use a CheckEmployeeRole action built-in the platform as an action, and you also can do it on client side, rather than doing it on server side.

For that, I would suggest you to have a variable of type Boolean to hold if user has the HREmployee role, for example IsEmployee. Then on the OnInitialize event of your screen you add the following JavaScript to get if the user has the Employee role and assign it to the variable, something like this:

 

After that, you just have to enclose your button on the if and set the variable as your condition:


In this simple way, you can do it on client side instead of server side and take full advantage of Reactive.


Kind regards,
João