Constants in XPath constraints

4
I've got the following statement in my XPath constraint (in a dataview): createdDate >= '[%CurrentDateTime%] - 6 * [%MonthLength%]' Now I'd like to replace the '6' by a constant, like: createdDate >= '[%CurrentDateTime%] - @Module.Months * [%MonthLength%]' This doesn't work. I get 'Multiplier in token expression must be an integer' in the XPath editor. When I turn things around like: createdDate >= '[%CurrentDateTime%] - [%MonthLength%] * @Module.Months' I get an error while running the app. How do I solve the problem? Thanks!
asked
6 answers
3

Try to make an "Create variable" activity with the value of the constant before your retrieve activity and use this output variable in your Xpath constraint

answered
2

Tijl,

From the Mendix documentation, it doesn't appear that constants can be used in XPath constraints, only in microflow expressions and to do things like identify the location of imported webservices. Documentation can be found here: Constants Documentation

Mike

answered
2

Tijl - I have wanted to use variables in XPath constraints before and haven't found a way to do it.

For your case above, you could create a calculated attribute on your entity. In the microflow for that attribute, perfomr the calculation above. Then in your XPath, you could compare the CreatedDate to your calculated attribute.

A little roundabout, but I think it will work.

Mike

answered
2

Is there a fix for this issue?  it really shouldn't be hard to add placeholders in XPATH expressions?

So we can use clean constants instead of literals :(

answered
1

Hi Tijl, I have the same problem. Did you find any solution or workaround of this issue?

answered
1

It sure would be nice to be able to use variables or references from the containing dataview.

answered