Help! How can I return a list of entities filtered by the current logged in user?
Hello I’m new to Mendix and the concept of low level-programming. This is driving me crazy, basically, I’m trying to filter a list so only the records of the current user are shown on my homepage. I’ve created a new column called: “user_id” and updated my entity model to ensure the value is stored correctly. Likewise I created a custom “demo” user account – which has the username: “demo” followed by a securely generated password. I’ve tried filtering my list using: ‘[%CurrentUser%] ‘and $currentUser/Name but I can’t figure out why these aren’t working – logging these variables after logging in doesn’t work either – just shows an empty string. The Mendix documentation doesn’t help either, just stating: [%CurrentUser%] returns an object – but doesn’t specify what this object looks like or what the properties of this object contain? In terms of my microflows, “Microflow” retrieves the data from my Excel spreadsheet and “Make Unique” filters the list to ensure no duplicates objects have the same order ID. Filtering my list by username always seems to return an empty list – although this is probably due to my filter not working correctly. Please can somebody help? I’ve attached screenshots of this below: #
You don’t need to store the id or the name of the user on your entity (you can, but you don’t need to). What you could do is creating an association between your entity and the account entity. Make sure that this association is set when committing the object to the database.
If the objects in your database are associated with the account like this, you can filter in an xpath retrieve, comparing the association to CurrentUser.
Okay so I’ve managed to create an association to the account entity but when I go to inspect it inside of the database viewer there’s nothing there? How am I supposed to filter via xpath if there is no data coming from my association?
Here is a learning path teaching you something about entity access (the right for users to read/write on certain entities). There is also something in it about the association to the current user. It isn't much, but it will maybe help you understand how to use the current user token.