max and min, etc. with X-Path queries

4
When retrieving an object in a microflow Retrieve activity, is it possible for example to use the X-Path constraint to select the object of a given type with the maximum or minimum (say) value of a particular attribute, and if so what is the syntax? Functions "min" and "max" don't appear in the ctrl-space list.
asked
3 answers
6

You can sort on an attribute and choose to retrieve only one object (select 'First object only'). When you sort ascending on an numeric attribute, you get the object with the lowest attribute value. Also when you sort descending on that attribute, you get the object with the highest attribute value.

In XPath constraints, it isn't possible to use the min or max function. In Java, it is possible to start your XPath query with an aggregate function, but then you can only retrieve the value of an aggregated attribute, not whole objects. At this moment, the only way to do this is the way I described.

The ways described in other answers and comments, are not real answers to the question. The question is to retrieve a real MendixObject instance, not only an aggregated value.

answered
2

It could be faster if you won't use the sorting, but execute a retrieve action and after that use an list aggregate activity.
The microflow engine will optimize these two activities is if they are 1 single xpath aggregate action.

Just make sure you retrieve the list and execute an list aggregate activity directly after the retrieve an it should work exactly the same as Jonathan says, but this solution also works for the count, sum, and average expressions.

answered
0

Yes that's possible. You can use the logical operators < (=smaller than) and > (=greater than) like this in your Xpath constraint:

[NrOfDownloads > 0 and NrOfDownloads < 100]

You can also use the operator <= (smaller than or equal to) and >= (greater than or equal to).

answered