Xpath error with empty variable and contains when it shouldnt (?)

0
We've a simple, but perhaps smart retrieve that allows queries to be empty or searched on when they're not empty. One of them that I'm struggling with is the following: [$LastName = empty or contains(PersonName, $LastName)] Basically; If $LastName is empty, retrieve all objects (because it's pretty much equal to having no XPATH expression) or retrieve all objects of which the attribute PersonName contains something matching the $LastName variable. Normally  “$X = Empty or $X is equal to X” is great for having multifunctional retrieves, as it uses the ‘XPATH should return true’ principle. However.. when my variable ($LastName) is empty, it should be true on the first query ($LastName =  empty), but it gives an error instead.  Why does this error occur? What am I missing? It would seem it's completely skipping the ‘$LastName = empty’ and wants to do a contains query with a NULL value, even though the value is simply empty and should match the first query ($LastName=empty)   (Yes, this flow has three parameters (_Id, Reference, LastName) and all of them are empty (on purpose). This retrieve was working perfectly untill I added the third expression (LastName) including the contains query) com.mendix.connectionbus.ConnectionBusRuntimeException: An exception has occurred for the following request(s): InternalXPathTextGetRequest (depth = 0, amount = 10): //Service_Data.Collection[NULL = empty or NULL = 0 or NULL = _Id] [NULL = empty or NULL = Reference] [NULL = empty or contains(PersonName, NULL)] at RestServices.SUB_CollectionList_GET_Map (RetrieveByXPath : 'Retrieve list of Collection from database') at RestServices.WS_Collections_GET (SubMicroflow : 'Map Collections')  
asked
2 answers
0

I just tested this, and I believe this is a bug in Mendix, where the query is not being formed properly. A solution may be to create a variable with trim($LastName) and change the query to $LastName = '’ or contains(PersonName, $LastName).

answered
1

I believe this is a known “issue” What I use to circumvent this: I use a string  with length 0 as opposed to a null string.

Then the query works.

[$LastName = '' or contains(PersonName, $LastName)]

Hope this helps,

Andrej

answered