Retrieve object using GUID in XPath - Mendix Forum

Retrieve object using GUID in XPath

6

Idea

The retrieve operation from database XPath constraint should have the ability to retrieve by the object’s GUID.

Example:

 

Problem

There are a few times where we need to use the Mendix generated GUID to uniquely retrieve the object.

 

Workaround

Currently, we create an additional attribute on the entity named ObjectId and use an After Create microflow + Java action to retrieve the GUID and set it on the object. Then we can use a retrieve by DB on the ObjectId attribute. It would be nice if we did not need to make a new attribute and could just retrieve by the GUID.

asked
1 answers

We use the following java action in the cases we need this. 

// BEGIN USER CODE
List<IMendixObject> mxObjects = Core.retrieveXPathQuery(getContext(), "//" + ObjectType.getType() + "[id=" + ObjectId + "]");
if(mxObjects == null || mxObjects.isEmpty())
{
	return null;
}
else {
	IMendixObject mxObj =mxObjects.get(0);
	return mxObj;					
}
// END USER CODE

Created