HowTo: Retrieve an Object where id = $Id(type of Integer/Long)

0
  Retrieve an Object  from database by  id 。 XPath : [id = $Id] Error:Incompatible expression types: RatingEngine.Account, Integer/Long.          
asked
4 answers
5

Hi Tang,

I know it is old question but in case someone looks for this in the future here is an answer(tested on 9.5.1). As Narayana said you can use your custom java action for that. The method Core.retrieveId(getContext(), id) will get you what you need but you need to provide IMendixIdentifier. Find below a code snippet and screenshots which will help you achieve what you need.

  1. create java action
  2. create 2 parameters, one for your id and one for the entity you would like to be returned from the action

  1. Create type parameter for your second input

  1. then deploy your project for eclipse and add this code in the action
// BEGIN USER CODE
	
	try{
		IMendixIdentifier ident = Core.createMendixIdentifier(this.ObjectId);
		IMendixObject recivedObject = Core.retrieveId(getContext(), ident);
		return recivedObject;
	}catch(Exception e){
		return Core.instantiate(getContext(),Entity);
	}
	
// END USER CODE

Hope this helps.

answered
1

Hi tangd,

There is a function which returns a list of mendixObject or a single object 

you can use this in java action

List<IMendixObject> objectlist = Core.retrieveIdList(getContext(), ids);
IMendixObject myobject = Core.retrieveId(getContext(), id)
answered
0

you may want to create your own id for that (auto number is probably the easiest solution)

answered
0

There is a difference between a database-id of an object and an object’s id that is used in the real world. Mendix shields away the object’s ids because it is (mainly) for internal use and prevents the common mistake of using the id as a public id of an object. That being said, you probably have a valid usecase, so here is what you can do:

First in your microflow add a Java-action ‘getGUID’, like I do  here for my Email-object:

then you can use the ReturnValueName to compare it to the object’s id.

answered