Before commit event not working correctly when creating objects in Java

2
I have a microflow which calculates a field on an object, this microflow is set to run before commit. It works correctly if I modify or create an instance of my object through Mendix forms, however when I create multiple instances at once with a Java coded csv import using the CreateBatch class none of my fields are calculated. Is this normal behaviour or should events be triggered when commiting in Java?
asked
2 answers
5

Like Johan says, that is normal behavior. The create batch and the changebatch will never execute any events (only validationrules can be checked)

Johan gave two solutions:

  • Use Core.commit instead of the CreateBatch (will be slower).
  • Define the logic of the before commit event in your Java action (before you create the object using CreateBatch.create).

There is another way of doing this. You could keep your commit microflow because your probably want it to be executed when a user commits the object as well. And creating the logic twice can only result in mistakes or differences between the two.
You can just call the microflow from your java like this:

 Map<String,Object> paramMap = new HashMap<String, Object>();
 paramMap.put("InputObject", batch.getMendixObject());
 Core.execute(this.context, "ModuleName.BCo_Objectname", paramMap);
answered
4

This is normal behaviour. The CreateBatch does not trigger object events. If you want to have events triggerd please do the following:

  • Use Core.commit instead of the CreateBatch (will be slower).
  • Define the logic of the before commit event in your Java action (before you create the object using CreateBatch.create).
answered