Dynamic Xpath

1
Hi there, I was wondering if there is a way to build and submit a dynamic xpath or a way to use an xpath constraint against a list of objects. I am trying to use a multiselect for a field called type to filter a list view loaded via a microflow.  The entities loaded via the microflow have a single type entry but I would like a user to be able to choose multiple types and have the filter be applied in the xpath so it would end up being type = TYPE-A or type = TYPE-B without having to manually enter that in the xpath.  Is there a way to either dynamically build out the xpath for the retrieve or to have type IN my-list-of-types-selected?
asked
3 answers
2

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.

answered
2

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. 

https://www.mendix.com/blog/easy-xpath-retrieval-in-java/

https://forum.mendix.com/link/questions/90180

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:

xpath.subconstraint().eq(Subject.MemberNames.Subject_Site, site)

However I just can't get my head around, how to make it work for the one-to-many association. 

answered
0

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,

-Andrej 
 

answered