Is there a simple function to get the current online user's role?

The objective is to display a link or button 'only' if the user has a certain role. 


I've spent hours trying different combinations of

1. GetUserId() (Returns User Identifier), 

2.CheckRole(RoleId,UserId) (Returns a Boolean value (User or Not User),

3. GetUserRole (Server Action)

4.GetUserRole->hasRole (Available in Assign statements after Server Action)

5.System User Entity (User_Id, User_Name, User_Username,User_Password,User_Email...). 

6. User_Effective_Role (quoted in 2015 post here) does not exist in Service Studio 11

7. IdentifierToInteger(A_User) = IdentifierToInteger(CheckRole(A_User,GetUserId()))

There is a screen in which there are three roles which are permitted.

 For example Registered, A_User, B_User, C_User etc. Is there a function that 'simply' returns what is the current logged in user (from this device) Role? Not if the user is on the designated list of approved users.

Hi Raphael,


1) Is it that you are using the Reactive Web application?

2) If you are using the Traditional Web application - why are you not using the Check<RoleName>Role(UserId) action, is there any specific reason for not using this role check action?


Regards,

Benjith Sam

Hi Raphael,

We do have pre-defined system entities, which stores the information of Role, User and the assigned Role (i.e. User_Role) information for a specific user. The entity is defined in the System Module, you can access via manage dependencies as shown below.



Referring this system entities, you can create a function/Server action in which you will be passing an UserID as input parameter and within the function logic we will be searching for the Assigned User Role information by referring the above mentioned entities and as a output parameter get all the required role information.

Hope this helps you!


Regards,

Benjith Sam

Hi Raphael,


Your objective is to display the UI widget Link conditionally on the basis of logged in user Role?

In that case you have to just wrap the Link widget inside a IF widget as mentioned below and provide a IF Condition something like this:

Code Snippet

CheckAdminRole(UserId:)


Hope this helps you!


Regards,

Benjith Sam

Benjith Sam wrote:

Hi Raphael,


Your objective is to display the UI widget Link conditionally on the basis of logged in user Role?

In that case you have to just wrap the Link widget inside a IF widget as mentioned below and provide a IF Condition something like this:

Code Snippet

CheckAdminRole(UserId:)


Hope this helps you!


Regards,

Benjith Sam

This looks like it 'should' be the answer. However that function (CheckAdminRole(UserId:) ) does not exist in my Service Studio 11. Can you confirm that it should be available? Am I missing some dependencies?


Hi Raphael,


The function CheckAdminRole(UserId:) which I used is just an example. Basically its an action/function for User defined Admin role in my case (you will be having some other roles defined, use accordingly).



Hope this helps!


Regards,

Benjith Sam

Hi Raphael,

If it's ok with you to share the .oml solution, I can help you by doing the required code changes.


Regards,

Benjith Sam

Benjith Sam wrote:

Hi Raphael,

If it's ok with you to share the .oml solution, I can help you by doing the required code changes.


Regards,

Benjith Sam

I really appreciate your help. I have posted the .oml 


Solution

Hi Raphael,


The defined IF widget condition looks correct. Please Logout the user and re-login the user and please make sure that the Logged-in user should not  be assigned with the BookingsResponsible Role (try to check the assigned User Role using OutSystems Users Application). 


PFA - .oml solution

Hope this helps you!


Regards,

Benjith Sam

Solution

Benjith Sam wrote:

Hi Raphael,


The defined IF widget condition looks correct. Please Logout the user and re-login the user and please make sure that the Logged-in user should not  be assigned with the BookingsResponsible Role (try to check the assigned User Role using OutSystems Users Application). 


PFA - .oml solution

Hope this helps you!


Regards,

Benjith Sam

Thank you very much Benjith Sam. In theory this is the actual solution to the problem. I did not configure the roles and permissions correctly in the Users Application. However your suggestion to use the :

Code Snippet:

CheckAdminRole(UserId:)

which is a server action called in the Preparation was the most efficient way to solve the problem.


And all that was necessary afterwards was to  insert this Action's result into the IF statement of the expression link.