How to get current user role and use it in a decision

0
Hello, I'm still very new to Mendix and I'm running into some issues. I've got 2 roles that represents in what division the user works within a company. The end goal is to create an object that stores that division when the user submits a form.  I just can't seem to retrieve the current user role and use that in a decision so that the correct data gets stored.   I know what I'm trying to achieve using traditional code, so I'll add that for extra context:   if userRole == "Role1" {     string var = "Division1"; } else {     string var = "Division2"; }   After that I would need the var to create an object.   Unfortunately my efforts to achieve the same in a Mendix microflow have failed, and I'm hoping someone can help me with this.   Mendix version: 10.4.1   Thanks in advance!
asked
2 answers
0

Hello Cédric,

 

If i understood it correctly, you want to know the role of the user and then connect it to the correct division, and if that is the case you can retrieve the role of the current user from the database, by doing a retrieve in System.UserRole with the Xpath [System.UserRoles = $currentUser]. The output will be a list containing all the roles the user has and you can apply a find for a specific role and in the find you will get an object that you can user in the decision.

If this doesn't help let me know so i can try to help you in a better way.

 

Hope it helps, 

Rui Cunha

answered
0

Similar to Rui's answer, you can retrieve the UserRole by XPath

[System.UserRoles = $currentUser]

[id = '[%UserRole_Role1%]']

 

By referring to the id of the user role, you make it robust for role name changes. This instead of filtering the list of all roles by name.  

answered