Retrieve data from variable entities

Hi all, I’m working on a sort of business rule engine. The rules are defined based on entities and attributes from the domain model with the use of the MxModel reflection. This part goes fine and I’m able to setup different rules.  The next step is to check if a certain situation meets the rules which are being setup. In this part lays the challanges, since a rule can be based on basically every entity and attribute. In order to check this, I need to retrieve a variable attribute from a variable entity and check the value of it. However, in Mendix is it necessary to specify what entity you want to retrieve. This is something that I want to avoid, since this is a lot of repeating work but more important, more and more features (read entities) are being added to the app which could be used to setup different rules. I want to make this part dynamic with variables. I have the name of the entity and the attribute in the microflow available with the use of MxModel reflection.  In other words; my question if it is somehow possible with Java to retrieve data from an antity based on the name of the entity, without hardcode defining what data I expect back?    Thanks in advance! Herrald
2 answers

If you want to apply your business rule(s) on a single object, and you know the object's GUID (because you saved its GUID somewhere, after getting it through e.g. CommunityCommons.GetGUID), you could use the following code to retrieve the object (belonging to an arbitrary entity):


		IMendixIdentifier newID = Core.createMendixIdentifier(Integer.parseInt(GUID));
		IMendixObject newObject = Core.retrieveId(getContext(), newID);

This saves you some trouble with XPath, but it’ll be hard to pass such an object back to a microflow.

You could test it by creating a Java action with an object input and doing:


		IMendixIdentifier initialID = inputObject.getId();
		String GUID = initialID.toString();
		IMendixIdentifier newID = Core.createMendixIdentifier(Integer.parseInt(GUID));
		IMendixObject newObject = Core.retrieveId(getContext(), newID);



Yes it is possible. You can do generic retrieves in java. There are multiple retrieve actions in the Core class. You can use one or the other, depending on what you want to achieve. You can create your xpath based on the information you get from MxModelReflection.

You will get an IMendixObject (Or a List of IMendixObjects). With this IMendixObject you can do whatever you want. If you have the names of the attributes from the objects of ModelReflection you can read or manipulate data on it.