Retrieve object by id-string in modeler

2
Why is it possible in widgets to retrieve an object via an ID string in an xPath, while the retrieve action in the modeler gives 'incompatible expression types: [object], String?
asked
3 answers
0

Remco,

No need to get the id in the Modeler.  In your Xpath, you can use the attribute name id.  So if you have the object you are trying to retrieve in a microflow as $ObjectName, your Xpath can look like this:

id = $ObjectName

Is there a requirement you have where that won't work?

Mike

answered
0

If you need to use the actual guid then you'll have to do it via java. 

I think this question will help:

https://forum.mendix.com/link/questions/82692

answered
0

Writing a custom java action might be able to achieve this:

 

Note that ObjectId is the id (int/long) passed in as a parameter for the java action:

@java.lang.Override
	public IMendixObject executeAction() throws Exception
	{
		// BEGIN USER CODE
		List<IMendixObject> results = Core.createXPathQuery("//<insert-module-here>.<insert-entity-here>[id=$value]")
				.setVariable("value", ObjectId)
				.setAmount(1)
				.setDepth(1)
				.execute(context());
		IMendixObject ProjectObj = results.get(0);
		return ProjectObj;
		// END USER CODE
	}

This retrieves the first object from the list of objects returned from the function createXPathQuery.

Of course, if the id is unique, there should only be 1 item returned in the list - results

answered