Referencing Entity Attributes in a Custom Widget

0
I am building a custom widget and want to retrieve a list of entities from Mendix to display in a table. To achieve this, I have prepared the following XML and configured the widget in Mendix Studio Pro. Additionally, I implemented the following code in JSX to fetch the list of entities. However, when I try to retrieve an attribute's value and check it in console.log, it appears as undefined.What is the correct way to access the attribute values?   xml <propertyGroup caption="General"> <property key="EntityList" type="datasource" isList="true" required="true"> <caption>Entity List</caption> <description>Sample text input</description> </property> </propertyGroup>   jsx const data = EntityList?.items || []; const dateAttirbute = new Date(data.DateTime);  
asked
1 answers
0

Hi,

 

If you want to access attributes in a datasource, you need to specify attribute properties in your widget XML and reference them to the datasource

 

https://docs.mendix.com/apidocs-mxsdk/apidocs/pluggable-widgets-property-types/#attribute

 

An example:

 

<property key="myStringProp" type="attribute" dataSource="EntityList" required="false">
    <caption>My property</caption>
    <description>My property description</description>
    <attributeTypes>
        <attributeType name="String"/>
    </attributeTypes>
</property>

 

To get the value in your widget code:

props.myStringProp.get(item).value

For decimal or date, use displayValue to get formatted value

 

The item is one item in your datasource items array so you need to loop over the array in your widget code using standard JavaScript for loop

 

answered