Executing parameterized OQL with java action

0
Hello Experts,  I have a created an OQL with 1 parameter. I want to execute the OQL with parameter in java action I am following https://docs.mendix.com/howto/extensibility/howto-datastorage-api#4-retrieving-objects-using-oql-specified-in-a-dataset Although the java action is able to execute the OQL the parameters set was not applied to the OQL. Some pointers on how to pass the parameters to OQL in java action is highly appreciated.         IOQLTextGetRequest oqlGetRequest = Core.createOQLTextGetRequestFromDataSet(this.DataSetName);         IParameterMap parameterMap = oqlGetRequest.createParameterMap();         parameterMap.put("Param1", this.PermitParameter1);         oqlGetRequest.setParameters(parameterMap);         String oqlQuery = oqlGetRequest.getQuery();         IDataTable resultDT = Core.retrieveOQLDataTable(getContext(), oqlQuery);
asked
2 answers
1

I looked in the below link to understand how the OQL appstore widget was developed. 

This widget takes the OQL query as a String and not a data set. Later they apply the parameters to the OQL query. 

https://github.com/reinouts/oqlmodule/blob/4c58bc9abf40dbfb892815deac47412b71797fa7/javasource/oql/implementation/OQL.java

I was using OQL as dataset. Although I followed the same approach, the parameters were not applied. 

But the OQL appstore widget helped me understand that I must use the Mendix ID to pass in place of object parameter in the OQL. 

Voila, that was easy for me as I already had java class to retrieve Mendix Id. 

Since, I had only one object parameter, I passed the Mendix ID and replaced the OQL query parameter with String replace method. 

Ofcourse, this solution could be scaled a lot. But for now, it works and fits my need.

Thought of updating so others could be benefitted.

 

answered
0

Check out the OQL module in the App Store. It may already do what you need. If not, the source code is available on GitHub for you to reference.

answered