Change input object from within java action possible?

Hi community, Say I have a java action: popFirstElement The input is a list. The output is the first element of the list. The expected behavior of the function is to get the first element of the list and to remove it from the list. I want to return the first element, but also change the list so it no longer contains that first element (standard pop function).   I’m looking for similar behavior as if I would pass a variable to a sub microflow: if I change the list in the sub microflow, it will still be changed in the main microflow, while still returning the object that I want. Simplified java action function: // This file was generated by Mendix Modeler. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package java_actions.actions; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; import com.mendix.systemwideinterfaces.core.IMendixObject; /** * Removes the first element from the list and returns it. If input is an empty list, assertion is thrown. */ public class PopFirstElementFromList extends CustomJavaAction<IMendixObject> { private java.util.List<IMendixObject> InputList; public PopFirstElementFromList(IContext context, java.util.List<IMendixObject> InputList) { super(context); this.InputList = InputList; } @java.lang.Override public IMendixObject executeAction() throws Exception { // BEGIN USER CODE IMendixObject firstObjectInList = InputList.get( 0 ); InputList.remove( 0 ); return firstObjectInList; // END USER CODE } /** * Returns a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "PopFirstElementFromList"; } // BEGIN EXTRA CODE // END EXTRA CODE } How can I make my java action so it returns the object I want while still changing the input list so it no longer contains the first element?
1 answers

Hi Alex,

I'm no java buff but could you elaborate why you would use a java action when this is also default available in Mendix?

With List Operation ‘Head’ you get the first element.

To get the remaining list you have two options, Change List action and remove your recently retrieved FirstElement from List, or use the List Operation Tail on your initial list to get a new list without the first element.