The way you describe your challenge, a regular solution is: a retrieve, followed by a loop, in which you have the iterator-object containing the attributes.
However, for some reason (performance), you want only 1 or 2 attributes and perform some action.
So then your best bet is to use OQL. This almost always gets you the most specific attributes and in the fastest way. If you have little experience, try https://service.mendixcloud.com/p/OQL to play-around, but your OQL-statement will look something like this:
from YourModule.YourEntity ye
where ye....somestatement...
select ye.Name, ye.BadgeNumber
A java-action is the best option, take a look at community commons “clone” java-action.
Hi David,
You can achieve this using OQL statement.
Check this blog
Thanks Everyone,
Apologies - I think I could have been clearer in my initial question. My requirement is to create a Word document based on the attributes of an entity in the Mendix database. Getting the entity and the data is the easy bit.
I'm using Ivo Sturm's Word Template module from here: How I Automated Microsoft Word Templating in Mendix Using The Apache POI API | by Ivo Sturm | Mendix Community | Medium and it works brilliantly (thanks Ivo!) but I want to map the attributes within my entity to the placeholders in the table that the Word Template module creates so that I can change this mapping if the data or entity structure changes.
The idea is that the mapping can be done by the user in a list / grid on a template managment page, so the user can say $Entity/attrubutname maps to <placeholder> in the document.
So, in my example, I have a placeholder in my document called <worker_name> that I want to map to the 'FirstName' attribute in my entity. When the document is created the Workers first name is extracted from the entity and added to the document. If my user requirements change and I have to map the <worker_name> placeholder to (for example) the 'FullName' attribute I'd like the user to be able to edit the mapping and it pulls the value of 'Fullname' from the entity.
I can hard code the mapping, of course, but it seems really inflexible and hard to manage. I can loop through the placeholder list and send the object and attribute name to a Java Action with Model Reflection but that doesn't seem very performant. Ideally, I'd like to be able to do something like <placholderdata> = $Entity/ + 'attribute_name' but I don't know if that's possible.
Sorry for the long winded addition - hope that clarifies things a bit!
David,
One idea is to use the Java action GetOriginalValueAsString from Community Commons. This Java action will retrieve the last committed value for a combination of Entity(Object) and Attribute name. So if you have the object, and you can get the attribute names from Model Reflection, you can retrieve the value of that attribute on a specific object.
I may be missing what you are trying to accomplish, but it seems this might work?
Mike