Retrieve an object by id

0
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.
asked
4 answers
2

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:

  1. Create a new attribute for that Entity like UUID
  2. This UUID can be auto number or you can fill it with you own logic
  3. Instead of database id property, which has security risks, you can use this UUID
  4. Like [UUID = $UUID]
answered
1

[id = $Id] isn’t working?

What I am wondering is, why do you need the id? Did you don’t have an object?

answered
1

You can create a java action and retrieve the object using the retrieveId method:

https://apidocs.mendix.com/8/runtime/com/mendix/core/Core.html#retrieveId(com.mendix.systemwideinterfaces.core.IContext,com.mendix.systemwideinterfaces.core.IMendixIdentifier)

answered
1

The Validation Feedback Collector in the appstore has a Java Action that will just do that.

answered