I am using Mendix 8.7 and would like to retrieve an object by it’s id. I have the id, by using getGUID from CommunityCommons, but I can’t work out the syntax to use in the XPath constant panel in the Retrieve Object activity. Can you provide some examples? I have the id as an integer/long or as a string.
You can create a java action and retrieve the object using the retrieveId method:
What I am wondering is, why do you need the id? Did you don’t have an object?
The Validation Feedback Collector in the appstore has a Java Action that will just do that.
I think you almost got it. If you want to convert a string to integer, you can create a variable of type integer and use parseInteger($s_id). Then use that variable in XPATH. But please do remember this compromise the security of the application.
Another standard way to do this if you are not too stubborn with ID implementation:
Create a new attribute for that Entity like UUID
This UUID can be auto number or you can fill it with you own logic
Instead of database id property, which has security risks, you can use this UUID