Core.createXPathQuery fails with string contains : Unknown predicate function expression

2
Hi, I was just writing some query code in java and can’t find the problem why this does not work. Core.createXPathQuery("//Module.Entity[contains(Name, $search )]") .setVariable("search","xyz") .execute(getContext()) this one fails with: Unknown predicate function expression type of second parameter: $search anyone an idea what I’m doing wrong here?
asked
2 answers
2

The search variable doesn’t seem to be replaced in your example.

Can you work around it by building the XPath as a string before executing it? This worked for me where this.Name was a parameter passed to the Java action as a String.
 

Core.createXPathQuery(String.format("//MyFirstModule.Entity[contains(Name, '%s')]", this.Name))
    .execute(getContext());



 

answered
2

Only think I see missing is the context not being passed to the execute function, but I bet that is just a mistake in your error code. Did you try removing the extra space? Or even executing it without the setVariable and just with a hardcoded value?

answered