67
Views
7
Comments
Solved
Get list of all roles that logged-in user have
Question

Hi Everyone,

I am new to OutSystems. I am trying to get all roles for logged-in user and save them somewhere (maybe client variables or please suggest how to save this info on client side) to use throughout application (instead of checking on each page). 

How can I achieve it in best possible way (maybe after login). I am working on O11.


Regards,

Rahul Singhal 

2024-09-12 02-43-38
Deepsagar Dubey
Solution

Hi @Rahul Singhal 

You can achieve it by these two system entities - Role & User_Role


 and apply these two filters



I hope it'll help you.

Thanks
Deep

UserImage.jpg
Rounak Rawat
Solution

Hii @Rahul Singhal,

I have applied the requirements that you want on login, on the screen and saved the name of the roles of login user.

Hope it will helps you. You can ask for any other query you have.

Thanks,

Rounak Rawat 


GetUserRole.oml
UserImage.jpg
Rahul Singhal

Thanks a lot @Rounak Rawat. Worked like a charm. Made just 1 change, used a switch in loop to set Boolean client variables for each role. 

UserImage.jpg
Rounak Rawat

I am glad it worked for you, if you need anymore help you can ask me. 

Regards, 

Rounak Rawat.

2025-12-04 09-01-03
Kiet Phan
Champion
Solution

Hi @Rahul Singhal 

There is a system entity called User_Role in the System Module. You can use Aggregate or SQL to get it.

  1. SELECT 
  2.     {Role}.[Name], 
  3.     {Role}.[Description] 
  4. FROM 
  5.     {User_Role}
  6. INNER JOIN 
  7.     {Role} 
  8. ON 
  9.     {User_Role}.[RoleId] = {Role}.[Id]
  10. WHERE 
  11.     {User_Role}.[UserId] = @UserId


UserImage.jpg
Rahul Singhal

Thanks @Kiet Phan. Only change is that column names are Role_Id and User_Id in User_Role entity. 

2024-09-12 02-43-38
Deepsagar Dubey
Solution

Hi @Rahul Singhal 

You can achieve it by these two system entities - Role & User_Role


 and apply these two filters



I hope it'll help you.

Thanks
Deep

UserImage.jpg
Rounak Rawat
Solution

Hii @Rahul Singhal,

I have applied the requirements that you want on login, on the screen and saved the name of the roles of login user.

Hope it will helps you. You can ask for any other query you have.

Thanks,

Rounak Rawat 


GetUserRole.oml
UserImage.jpg
Rahul Singhal

Thanks a lot @Rounak Rawat. Worked like a charm. Made just 1 change, used a switch in loop to set Boolean client variables for each role. 

UserImage.jpg
Rounak Rawat

I am glad it worked for you, if you need anymore help you can ask me. 

Regards, 

Rounak Rawat.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

Using User_Role is NOT correct! You need to use User_Effective_Role which is a view that only includes roles that a user indirectly has through a User_Group assignment.

Regards,

Daniel

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