I want to access mendixsystem$attribute entity and list the attributes of MyFirstModule.Entity in a drop down. How can I access this in modeller?

0
1. I want to access attributes of mendixsystem$attribute and mendixsystem$entity from modelller. 2. How can I display the attributes of MyRepository.FirstEntity in a dropdown.   Admin selects the attributes from dropdown which can be edited by the user. Now when user logs in, the review page should dynamically display these attributes along with their values. Drop down is nothing but attribute names from an entity. How can we compare values to entity attribute names and display values? Please suggest.
asked
3 answers
1

Hi Priyanka,

This can be done by using the MxModelReflection module from the app store. This provides the representation of all entities, associations, attributes and microflows.

https://appstore.home.mendix.com/link/app/69/Mendix/Mx-Model-reflection

KR,
Bart

answered
1

Hi,

 

Regarding your second question MxModelReflection is exactly what you need. Now in order to display a dropdown you can not use an enum (unless you want to hardcode the attributes for your entity there, which completely misses the point IOP if you want it to be dynamic and reusable for other entites). Instead you need to use a reference selector.  This is how I would do it:

Make an association between your entity and the MxObjectMember entity and use the attribute "AttributeName" to select by. Use XPath constraint o only show attributes for the data view entity

 

If you want to avoid hardcoding the module and entity name, you need to use a java action to retrieve the name at runtime.

 

Hope this helps,

Andrej

 

EDIT PS: In java you can get the CompleteName for an entity which consists of the module name.entity name e.g. "MyFirstModule.Employee" from an IMendixObject imo using

`imo.getType();` Make sure to pass "Any object" as parametar to your java action.

 

answered
1

Hi  Priyanka,

MxModelReflection only goes so far. You would need a custom solution to achieve what you want. 

The simplest solution I can think of is to define another entity e.g. AttributeValue that holds the value for a specific attribute as a string. To get an attribute value as a string you can use the CommunityCommons library or write your own java action that just calls "toString()" or "parseValueToString()" on the appropriate attribute member.

Here is minimal working example to help you out:

 

Using a microflow as datasource was easiest for me to implement but you can choose a different approach, perhpas get all the values in a before commit attribute.

 

Here is a screenshot of the end result

 

And here is what I have selected to be shown.

 

I hope this helps,

Andrej

 

PS; Here is the datasource microflow

https://modelshare.mendix.com/models/e2927c5c-19a0-485a-8a2e-4fdb0edea864/d-s-get-attribute-value

answered