Retrieve Object from Database with a certain ID

2
Hey guys, I want to retrieve an object from the database where the ID is equal to a certain object ID. Mendix doesn’t allow me to compare the ID with an integer value, it always wants the object itself for comparison.  Is it possible to do that ?  
asked
2 answers
4

Solution: add an attribute (say MxId) to the entity and copy the id to MxId after object-creation.

It is not possible via the retrieve-activity. Mendix obfuscates this id on purpose as part of being a lowcode platform. Mendix kind of wants you to never have to use this internal id-value (certainly not change it).

An alternative is to retrieve a list, use communitycommons.getGUID to check if you have the one you want, but this far from optimal:

https://modelshare.mendix.com/models/2f536d4d-b23b-42fd-84c6-1236ef1cb21a/microflow

Also this is not possible via OQL. The OQL does not allow to select on id:

 

So all you can do is add an attribute (say MxId) to the entity and copy the id to MxId after object-creation. Then it easy: retrieve with XPath [MxId = 2082914827]

answered
3

Hi,

you could easily write a Java Action to do this:

return Core.retrieveId(getContext(), Core.createMendixIdentifier(objectId));

However in most cases its better to explicitly define a unique identifier in your data model as suggested by Tim.

regards, Fabian

answered