changedDate is not updated when object commited in Java.

0
Hi, guys =)   I have a question regarding update of changedDate attribute.   I got a ParentEntity with all system members included. And a ChildEntity, which is a generalization of ParentEntity.   When I change and commit ChildEntity object in Java action, changedDate attribute is not updated. If I update ChildEntity object with demo_user on ChildEntity edit page, changedDate is updated. After commit in Java attributes are updated/saved both for Parent and Child entities, but not changedDate. I also checked whether this is an issue with the context I work with on Java level. I've tried getContext(), Core.createSystemContext() and Core.login("demo_user", password).createContext() and none of these contexts worked for me. Any thoughts/ideas how to solve it?  
asked
3 answers
0

can you put the peice of code which you are using for commiting the changes in java action here.

 

answered
0

Here is the code of executeAction method in Java action
 

	@java.lang.Override
	public java.lang.Void executeAction() throws Exception
	{
		this.issueToChange = this.__issueToChange == null ? null : issue.proxies.Issue.initialize(getContext(), __issueToChange);

		// BEGIN USER CODE

        final boolean isSomethingBoolean = issueToChange.getSomethingBoolean();

        issueToChange.setSomethingBoolean(!isSomethingBoolean);
        issueToChange.commit(getContext());
        //issueToChange.commit();
        return null;


		// END USER CODE
	}

 

answered
0

There's an undocumented method MendixObject.updateSystemAttributes(IContext)
It is the only method that updates the system attributes and it is only called from the microflow action "Change object". The most legal way to achieve the desired result is to call a microflow from your java code and in that microflow to change the object. However, you would have to create a microflow for each object type you want to change from java.

 

The not so legal way is to create your own implementation of updateSystemAttributes in your java code and set the system members by their name:

obj.getMember(iContext, "changedDate")).setValue .. . new Date
obj.getMember(iContext, "System.changedBy")).setValue ... context.getSession().getUserId()

 

You can call obj.isChanged to check whether you want to update the system members.

 

The least legal way is to get access to the method updateSystemAttributes  with obj.getClass().getMethod because the method is public.

 

answered