Get object attribute value when the attribute name is a variable - Mendix Forum

Get object attribute value when the attribute name is a variable

1

 

We can retrieve the attribute value of an object using attribute name; like:


$Studnet/Name

$Studnet/Department

$Student/RollNo

 

But what if the attribute name itself in variable ? like:


$Studnet/$AttributeName

 

Currently Mendix do not support passing attribute name as an object. Here we can achieve this feature using a simple JavaAction.

 

Create a JavaAction from menu, namely:JA_GetMembers and pass two parameters; in above example the Entity will be 'Student'

MyCustomEntity - Object of the entity where we need to retrive attribute value.

ParamName - Parameter to identify the name of attribute

image.png

 

Use 'Deploy for eclipse' as we usually do for Java Actions; then edit the newly created java action. Add below code under 'BEGIN USER CODE'

image.png

 

Done!, Now this JavaAction can be called from Microflow as shows below:

image.png

 

Posted
1 comments

// BEGIN USER CODE  

     var member = this.__MyCustomEntity.getMember(getContext(), this.ParamName);        return String.valueOf(member.getValue(this.getContext()));    

    // END USER CODE

Created