I think the only way to do this is by doing your retrieve in a java action. In a java action, your xpath is just a string. This string can be created based on whatever you want. In the modeler, it is always hard coded. You can turn statements on and off by using booleans and “and” operators, you can also compare to dynamic data, but you can not dynamically create the whole compare statement. In a java action you can do this.
Since there are not much Java code snippets using the new XPath method in Jave here a code snippet from Java where you pass the entity name and attribute as string and an XPathParameter to look for.
if (xpathParameterString == "empty") {
xpathString = "//"+entityName+"["+attribuutString+"="+ xpathParameterString+"]";
}
List<IMendixObject> resultList = Core.createXPathQuery(xpathString)
.setDepth(1)
.execute(context());
return resultList;
Regards,
Ronald
Hi,
thanks for your answers Andreas and Ronald. However, I’m having trouble implementing your code Ronald.
I hard coded some stuff for testing, but when trying to create a "List”-object, I get a compilation error (“symbol not found”), telling me that the class List can not be found (see below). I tried importing some more classes but I had no success. Otherwise, the code seems pretty clear to me and should work..
Which version of Mendix are you referring to? Maybe it is a version error.
Thank you in advance
Jan
My Code: I added the Core import and declared the xpathString variable:
// This file was generated by Mendix Modeler.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package myfirstmodule.actions;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
public class Masterflow_Method_Simulation_JavaAction extends CustomJavaAction<java.util.List<IMendixObject>>
{
private java.lang.String XPathParameterString;
private java.lang.String AttributeName;
private java.lang.String Threshold;
public Masterflow_Method_Simulation_JavaAction(IContext context, java.lang.String XPathParameterString, java.lang.String AttributeName, java.lang.String Threshold)
{
super(context);
this.XPathParameterString = XPathParameterString;
this.AttributeName = AttributeName;
this.Threshold = Threshold;
}
@java.lang.Override
public java.util.List<IMendixObject> executeAction() throws Exception
{
// BEGIN USER CODE
throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented");
String xpathString = "";
if (XPathParameterString == "empty") {
xpathString = "//"+"MyFirstModule.CRM"+"["+"IndustryCode"+"="+"2"+"]";
}
List<IMendixObject> resultList = Core.createXPathQuery(xpathString)
.setDepth(1)
.execute(context());
return resultList;
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "Masterflow_Method_Simulation_JavaAction";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}
Error:
Buildfile: C:\Users\xxxxx\Documents\Mendix\xxxx\deployment\build_core.xml
compile:
[javac] Compiling 2 source files to C:\Users\xxxxx\Documents\Mendix\xxxxx\deployment\run\bin
[javac] C:\Users\xxxxx\Documents\Mendix\xxxxx\javasource\myfirstmodule\actions\Masterflow_Method_Simulation_JavaAction.java:41: error: cannot find symbol
[javac] List<IMendixObject> resultList = Core.createXPathQuery(xpathString)
[javac] ^
[javac] symbol: class List
[javac] location: class Masterflow_Method_Simulation_JavaAction
[javac] 1 error
BUILD FAILED
C:\Users\xxxxx\Documents\Mendix\xxxxx\deployment\build_core.xml:29: Compile failed; see the compiler error output for details.
Total time: 1 second