Retrieving data from Mendix Database in Java Action

0
Hi, I am new to Java Actions. My use-case is: I have a String ‘Name’ &  a String ‘Type’. In my Java Action, I have to search my Mendix Data & retrieve the Objects having the name as ‘Name’ & Enum value for type as ‘Type’. How should I proceed for it? I am assuming I will have to create an Xpath query & retrieve the data using retriveXPathQuery function in the Java Action. But I am not able to use if appropriately. Can anyone provide a sample example for this case? Pls .help. Thanks
asked
4 answers
1

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

answered
0

Hi Purva,

There is a forum post that already answer your question, please can you have a look into this forum post.

 

Hope this helps!

answered
0

Hi Purva,

Have a look at the documentation in the Core for createXPathQuery, it gives a good example which I’ll repeat here.

 public getObjectsWithValue(IContext context, ICore core, int value) {
     List<IMendixObject> results = core.createXPathQuery("//Entity[attribute=$value]")
         .setVariable("value", 1)
         .setAmount(500)
         .setOffset(50)
         .setDepth(1)
         .execute(context);
     return results;
 }

You just need to adjust this to match your query.

Hope this helps

answered
0

Hi

You can use OQL Queries inside JavaAction.

 

this.OqlQuery = "select * from Module.EnityName where where name='@name@'";
this.OqlQuery  = this.OqlQuery.replace("@name@", this.name);
IDataTable resultDT = Core.retrieveOQLDataTable(this.context, this.OqlQuery);
List<? extends IDataRow> rows = resultDT.getRows();
if(rows.size() != 0) {
	for (IDataRow row: rows) {
		String name = row.getValue(this.context, "name");
	}
}

 

answered