You can. It requires a bit of Java to do so. The process is: you build a query string, then you execute it with a java action that calls this function: https://apidocs.mendix.com/8/runtime/com/mendix/core/Core.html#createXPathQuery(java.lang.String)
And then from the java action you return a list of objects.
Right now I'm also looking into dynamic XPath creation and found that using the CommunityCommons XPath method as described in the following posts, best suits my needs as it allows for method chaining and we just upgraded our application from Mendix 6 to 7.
However as it is undocumented, I still got one challenge though. I just don't know how to get the following to work (see simplified example below).
[StudyManagement.Subject_Site = $Site] [DataCapture.SubjectVisit_Subject/DataCapture.SubjectVisit[ DataCapture.SubjectVisit_Visit = $Visit and (Status = 'Completed') ] ]
What I'm trying to do is to retrieve all Subjects that belong to the specified Site (many-to-one association) and that have a SubjectVisit (one-to-many association) which meets specific filter criteria.
For the many-to-one association I found, the following to work:
However I just can't get my head around, how to make it work for the one-to-many association.
A simpler alternative without java would be to make the filter object persistent and then store the filters as associated objects. This would then let you write a very simple XPath. To exemplify let's say you want to select all employees who are in a list of projects. Connect all project to a Filter object then query
//User[User_Project/Project/Project/Filter = $Filter]
This has an obvious performance hit in that the filter object needs to be committed every time before searching. So it is only applicable for low number of users, let's say up to 50.
Hope this helps,