XPath retrieve object problem: starts-with($Input_string, ObjectAttribute) is not allowed/possible

1
I want to retrieve a configuration object. The Code attribute of this object should match the start of the Input string that is provided. In a Xpath-retrieve, starts-with($Input_string, Code) doesn't work, because the first argument of the function should be a path and the second path a literal string or predefined variable. My problem is that the Code attribute is not of a static length, otherwise, I would have done a substring of the Input string and then just check $Input_substring = Code I was wondering if anyone knows of a solution other than retrieving all Configurations and looping through them to check whether the Input string starts with Iterator/Code.
asked
4 answers
2

The best solution I can think of is to use multiple consecutive retrieves, removing 1 character from the end of $Input_string  and using xpath like:

[Code = $Inputsubstring]

until you find a match or you hit some minimum length for $Input_string.

This model share should illustrate the idea:

https://modelshare.mendix.com/models/25f72c3f-83b2-4784-bf6a-54c61ccb7dc0/inverted-starts-with-retrieve

answered
0

Hi Martin,

Instead of looping through the whole list, you could also use a filter or find after retrieving the list. This way you don't have to loop over the list.

How many configurations are you expecting to retrieve from the database? if it aren't that many, I think this isn't a bad solution.

answered
0

Hi Martin,

I think you need to swith $input_string and Code. The first argument expects the attribute you want the function to match on and the second part the string value. 

Example: 

//Sales.Customer[starts-with(Name, 'Jans')]

 

So in your case this would result in [starts-wtih(Code,  $Input_string). Unless I missed something of course ;)

answered
0

Hi Martin,

I don’t have an ideal solution but if it looks like you’re forced to retrieve all configurations and loop through them then you can possibly refine that somewhat by combining it with a fixed substring retrieve also, so you only have to loop through a subset of Configuration objects and not all of them.

So if the minimum length configuration code is three digits then you could take the first three digits of the $inputstring as an $inputsubstring, do an xpath retrieve with starts-with(Code,  $inputsubstring) then loop through this subset of Configuration objects to check whether the Input string starts with Iterator/Code.

Might be worth it if you have lots of configuration objects but also in the future you wouldn’t want to introduce a new configuration with length of Code fewer than three digits.
 

answered