Java action create list

Hi All, Need to implement a java action which will return a list of objects.  For Example:  Record entity. I want to know how to initialize the list and also create Record entity within the java action. How to implements  this in mx java action. List<Record> records  = new ArrayList<>(); records.add(new Record);   Thanks in advance.
1 answers

Hi mohammed,

find the code below for creating and adding object to entity as a list. You can create multiple objects and add to the arraylist.

        ArrayList<IMendixObject> mylist = new ArrayList<IMendixObject>();
         IMendixObject newobj = Core.instantiate(getContext(), ListObj);
         newobj.setValue(getContext(), sam.MemberNames.num1.toString(), "2");;
        return mylist;
        // END USER CODE

sam.MemberNames.num1.toString()  – sam is an entity and num1 is attribute.
ListObj - the entity passed from the java action.

I have attached the screenshots of the java action and output. You can extend the code as you need, Hope it helps.