Java Action - IllegalArgumentException - Type Mismatch

0
Hello, I am implementing a Java Action which will be used to toggle the value of an association between two objects Equipment_Checks and Account (a subclass of System.User) to either null or [%CurrentUser%] (cast from User to Account).  Here’s a closer look:   The idea is for each of these associations between Equipment_Checks and Account to correspond with a button that the user can press when a certain task is completed, thereby showing that the task is done and by who.  Each of these buttons calls a unique microflow which casts [%CurrentUser%] to Account, then passes into this shared Java Action a string signifying which association value to change.  All of this setup is to explain why I am mostly using IMendixObject instead of proxies.  I hope to accomplish reusability by using the setValue() method rather than proxies’ set attribute methods.  Button_Action is the string parameter which signifies the association to change. public class JA_Delegate_To_Subaction extends CustomJavaAction<java.lang.Void> { private IMendixObject __Log; private briefinglog.proxies.Briefing_Log Log; private IMendixObject __Current_User; private custombyuaccount.proxies.Account Current_User; private java.lang.String Button_Action; public JA_Delegate_To_Subaction(IContext context, IMendixObject Log, IMendixObject Current_User, java.lang.String Button_Action) { super(context); this.__Log = Log; this.__Current_User = Current_User; this.Button_Action = Button_Action; } @java.lang.Override public java.lang.Void executeAction() throws Exception { this.Log = __Log == null ? null : briefinglog.proxies.Briefing_Log.initialize(getContext(), __Log); this.Current_User = __Current_User == null ? null : custombyuaccount.proxies.Account.initialize(getContext(), __Current_User); // BEGIN USER CODE IMendixObject currentTracker = Core.retrieveByPath(getContext(), __Log, Shift_Type_Tracker.MemberNames.Shift_Type_Tracker_Briefing_Log.toString()).get(0); String shiftType = currentTracker.getValue(getContext(), "Shift_Type"); IMendixObject equipmentCheck = retrieveBasedOnShiftType(shiftType).getMendixObject(); // type = Equipment_Checks IMendixObject equipmentCheckDoer = equipmentCheck.getValue(getContext(), Button_Action); // type = Account if (equipmentCheckDoer == null) { equipmentCheck.setValue(getContext(), Button_Action, __Current_User); // <--- EXCEPTION thrown here } else if (equipmentCheckDoer.equals(__Current_User)) { equipmentCheck.setValue(getContext(), Button_Action, null); } Core.commit(getContext(), __Log); return null; // END USER CODE } ... // BEGIN EXTRA CODE private briefinglog.proxies.Equipment_Checks retrieveBasedOnShiftType(String shiftType) throws com.mendix.core.CoreException { switch (shiftType) { case "Day": return Log.getDay_Log_Equipment_Checks(); case "Swing": return Log.getSwing_Briefing_Log_Equipment_Checks(); case "Graveyard": return Log.getGraveyard_Equipment_Checks_Briefing_Log(); default: throw new RuntimeException("Unaccounted for shift type"); } } // END EXTRA CODE } When given input “EAS_Test_Page”, this is the exception/stacktrace the action gives me. com.mendix.modules.microflowengine.MicroflowException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.IllegalArgumentException: The given value '[MendixObject:: type:CustomBYUAccount.Account id:[MendixIdentifier:: id=8444249301321181 objectType=CustomBYUAccount.Account entityID=30] state:NORMAL members: ... Blocked=MendixObjectMember, CustomBYUAccount.Account_Phone_Carrier=MendixObjectMember}' with type 'class com.mendix.basis.objectmanagement.MendixObjectImpl' is not of the same type as the member corresponding with the given member name 'BriefingLog.EAS_Test_Page' at BriefingLog.EAS_Test_Page (JavaAction : 'JA_Delegate_To_Subaction') I can’t find anything about ‘MendixObjectImpl’ in the javadocs.  Does this just need a simple cast?  If so, where?  Or perhaps I shouldn’t be dabbling in IMendixObject at all? I would appreciate any help and am happy to provide more info as needed.
asked
1 answers
1

To mark this question as answered, the answer to the issue was that the setvalue for the mendix object that was used to set a reference should be set with the ID of the object and not the object itself.

The line in the code should read like below:

equipmentCheck.setValue(getContext(), Button_Action, __Current_User.getId());

 

answered