Uncommitted data in objects not getting passed to javascript action

0
I am creating a javascript action that will create some audit entities, it will take 2 of the same objects (A copy from before changes and then the latest version after changes) and then compare them However I am getting an issue with the objects being passed, my "latest version" entitiy does not contain any of the changes and my duplicate also contains no data. (I have used a show message action before to confirm the duplicate does have data and it definitely does) I tested by committing the objects before calling the javascript action and it now works, however I don't really want to be committing the duplicate if I can help it.   How can I use the javascript action without committing the entities before?
asked
2 answers
0

hi,


In Mendix, JavaScript actions run on the client, and they receive object data from the client state only if the object’s current values are already stored in client memory. If the object you pass has uncommitted changes that are only in the nanoflow context, those changes may not be reflected when passed into the JavaScript action. This is a known behavior because the client API passed to JS can only see the object’s baseline state, not pending uncommitted changes.

Why this happens

  • Nanoflow creates or modifies an object in memory.
  • The JavaScript action gets the MxObject reference, but the changes are not yet committed to the client state representation the JS API uses.
  • As a result, in the JS code you see the original values, not the changed ones.
  • When you commit the object first, it works — because the committed state is stored and reflected in the client state passed to JS.

This behavior is described in community threads where passing a newly created or changed object to JavaScript will only reflect correct values when the object is committed.

How to fix it (working in Mendix)

Option 1 — Commit the object before passing

If you need to pass up-to-date values into the JavaScript action, do this:

  1. Commit object (commit only the target object)
  2. Then call JavaScript action with that object

This ensures the JS action receives the latest values.

Option 2 — Pass individual attribute values instead of the object

If you don’t want to commit, you can:

  1. Extract each attribute you need into separate parameters
  2. Pass those primitive values into the JS action

Example:

  • nanoflow variable: nameValue = $Object/Name
  • pass nameValue into JS instead of the full object

This works because simple values don’t depend on commit state.

Option 3 — Use local client state monitoring

In a browser, you can inspect the client state (Ctrl + Alt + G) to see what is currently stored and whether your uncommitted object is present. This confirms why the JS sees only the original values.

answered
0

You can avoid committing the duplicate object by linking it to the latest object using a self-association. This ensures the duplicate remains referenced in the client context and is not lost before the JavaScript action is executed.


After duplicating the object, set a self-association from the latest object to the copy. This keeps both objects connected in memory without requiring a commit.


Then pass the latest object and the associated copy to the JavaScript action. Since the copy is still referenced through the association, Mendix will correctly provide its attribute values even without committing it to the database.

answered