Filter a list view by the user name

0
Hello everybody, I have a table that contains information with a "UserID" column. How can I display in a list view, just the items corresponding to the user logged into my application : the elements of the table whose "UserID" is equal to the current UserName. Best regards, Omar.
asked
10 answers
4

You're falling into a trap common with developers coming from other data modeling paradigms that use foreign keys. Instead, in Mendix, you should be using associations between your entities. Your list view entity generally should not have a "User ID" field.

So, I would recommend that you create an association in your domain model between Administration.Account (your user), and entity in your list view. Source the list view via XPath, and set the XPath constraint to something like this:

[MyEntity_Account = ['%currentUser%']]

answered
1

You could source your list via microflow. Within the microflow you retrieve using Xpath and return the list.

answered
1

Hi Omar,

First I would check off the "Store 'owner'" System members in the entity in the Domain Model:

 

Then, set your listview's Data Source as a microflow. In that microflow, try doing a Retrieve from Database, set the entity to whatever entity has the UserID attached to it, and set the XPath to something like [System.owner = $currentUser]. Finally, set the return object(s) to the retrieve from database list.

 

Thanks!

Anthony

answered
1

Dear Omar, 

You can use an XPath constraint, depending on what kind of "return" objects you would like to add to the list. 
Please visit https://docs.mendix.com/refguide7/xpath-constraint-functions and look at the different constraints you can use. 

​Kind regards,
Raymond

answered
0

Hello Friends,

 

Thank you for your answers, that's o good solution, but i have also an other error. How can I set the return objects to the list ?

This is my example

Best regards,

Omar.

answered
0

Hello Raymond,

 

I used XPath method but it didn't work. On the image below, ApproverID is a column in my table that contains the login of the user. I want to display on my List View just the items corresponding to the user connected to my application.

Thank you,

Omar.

answered
0

Hello Raymond,

I used XPath but it didn't work. On the image below: ApproverID is a column in my table that corresponds to the login of the user connected to my application.

I want to display on the list view just the items corresponding to this user.

Thank you,

Omar.

answered
0

answered
0

Hello,

I have tried all these solutions, but it doesn't always work,

The problem is the syntax of the xPath, the field 'ApproverID' is a string and the currentUser is an object 'System.User'

Someone has an answer?

answered
0

Hi Omar, 

try [id=ApproverID] as Xpath Constraint.
Maybe this works. 

Raymond

answered