Hi Kofi,
As a workaround why dont you do the retrieve in a microflow and then call that microflow from java. Its much simpler to write the XPath that way and you will also be alerted when some Entities or attribute names change. I find this much safer than doing the retrieve in java. IOP you should use java only for the things that you can not do in mendix.
-Andrej
Agree with Andrej, but if you must do this in Java, you can also use the XPath generator class of the Community Commons module. See https://www.mendix.com/blog/easy-xpath-retrieval-in-java/
CustomerParameter1.getMendixObject().getId().toLong()
Related, Core now also has createXPathQuery and retrieveXPathQueryEscaped which you can use instead of building the entire String
var xpq=com.mendix.core.Core.createXPathQuery(
"\
//System.FileDocument[\
contains(Name,'$nam')\
and\
contains(Name,'$ext')\
and\
Size>$siz\
]\
"
);
xpq.setVariable("nam","a")
xpq.setVariable("ext","xls")
xpq.setVariable("siz",100)
xpq.setAmount(8)
xpq.setOffset(0)
xpq.setDepth(1)
xpq.setDisableSecurity(true)
xpq.addSort("Size",true);
var arr_obj=xpq.execute(context);
...
var xpathFormat="//System.FileDocument[\
contains(Name,'%s')\
and\
contains(Name,'%s')\
and\
Size>%s\
]";
var amount=1;
var offset=0;
var sort={};
var depth=1;
var arr_obj=com.mendix.core.Core.retrieveXPathQueryEscaped(
context,
xpathFormat,
amount,
offset,
sort,
depth,
"xlsx",
"a",
"100"
);