How to set up condition for visibility for a button depending on an associated System.UserRole

Hello!   I'm somehow stuck. The objects in my datagrid 2 have an association with System.UserRoles. That association specifies which role is allowed to approve / reject for that object. I added a custom column to the datagrid with a button. I would like to achieve that only the user with the associated role of this object can see that button and click it.    I tried it with condition for visibility but I can not find a way to retrieve the role of the current user.    Can somebody point out which direction I should look to solve this?      
3 answers

Hi Timm,


You can give visibility for the roles selected so that only those user will able to see that button for approval,



Hello Anne Timm,


Your current equation is UserRole = User which are different entities so first you need to make sure you equate the same entities, probably by retrieving the userrole, another problem that you probably will have to tackle is that userrole connected to the user is a 1-* relationship so it is a list instead of a single object, so what you probably are going to need is maybe some helper non persistent object or you need to have a look at the workflow functionality that mendix offers but maybe that functionality is too hardcoded for your business needs.


Hope this helps,


Good luck!


Thanks for the hint!


I was able to find a solution. Maybe not the ideal one but it seems to work. 

I retrieved the current user role(s) for the current user from db. I retrieved the allowed user role(s) from the approval object via association. This results in two lists. I create a intersect list. In the decision I check whether the list is empty or not. If there is no intersection object user roles, I simple return the first System.Userrole object from users userrole list. If the list is not empty I take the first userrole object of the intersection list. 


On the page I set the condition visibility to expression 

if $currentObject = $dataGrid21/ApprovalWorkflow.Request_Tour_Approvals_UserRole then true else false