Get Current User for XPath Data Source List View

For part of my application, I’m creating a list view where the information displayed is information that is only relevant to the current user. Originally, I was going to do this through the Association or even microflow data source, however that does not allow me to search through the list with something like multifield, which is a feature that I wish to include for this list view. I ended up coming up with attaching a string to the entity displayed in the list view, that is a list of users that the given information is relevant for. And then from there, I was hoping to have it with something like the following XPath expression, where ‘UserList’ is the list of users connected to the information. [contains($UserList, $CurrentUser/Name)] However, I noticed that for data source XPaths, the ‘CurrentUser’ variable does not seem to be accessible. Not only that, but XPath data sources do not seem to be able to pull from parent data widgets, so I can’t even nest the list view in a System.User dataview. Is there any way to access the CurrentUser variable in a data source XPath? If not, is there possibly another way to achieve this same goal so that I can utilize searching? Our project is not set up for server-side searching and paging through REST. We tried an alternate method of retrieving the list view information using a flag that was also attached to the entity, however when more than one user entered the page with the list view, it caused the information to glitch out and display improperly (someone else’s information was coming up on the given person’s page). Any help would be appreciated. Thanks!!
2 answers

On a Xpath constraint for a datagrid or the like you have to use different format to $currentUser to use the currentUser, currentObject or things like userroles. See XPath Keywords & System Variables - Studio Pro 9 Guide | Mendix Documentation


  • ‘[%CurrentUser%]’
  • '[%CurrentObject%]'
  • '[%UserRole_ThisRole%]'

However this won’t let you access attributes within these entities. You should not use a string of usernames to achieve what you want, it will cause you many difficulties. You should still use associations in the Domain model, but on the List View you can then use an Xpath source with constraint as one of the above keywords.

So it seems like you might have many information entities associated to many users who can see them. Then in the Domain model you could do an association from your entity to user *->*. Some logic to take the entities and add the association to the user you want to see it. When setting the association use ‘add’/’remove’ rather than ‘set’ as set will replace other associations to other users. Then your xpath constraint you might want to set on the list view as [Module.OtherThing_User='[%CurrentUser%]'].

However you should also consider the security of your app, if users would only have permission to see entities they are associated to then you would also set this association on the security page in the screenshot below. If this is set on the security for a userrole then you can omit it from the list view constraint as users would automatically only see objects the security allows. Remember setting an Xpath constraint on a list view or UI widget only affects that view, not the security of what objects users actually have access to. 

 So you definitely will want to use associations. It might be many to many *->* or many to one *-1 depending on your use case. You might also be using Administration.Account rather than System.User for your association if you prefer. Hope this helps.


What you have is '[%CurrentUser%]' and you can compare this with System.owner for the entities. A possible solution for you is to have the list of users in a separate entity(UserList) and you would need to asscoiate this new entity (UserList) to your main entity(which has the information), then you will be able to access the UserList in the XPATH