Get the Mendix Object GUID in Native

Question: Can I use NanoflowCommons.GetGuid JavaScript action to get the Object GUID in Native?

Answer: Yes. No. It depends.

The JavaScript action NanoflowCommons.GetGuid in Mendix Native returns the Object GUID when called in a Nanoflow, but it doesn’t always have the value you might expect. Let’s consider the following 3 scenario’s:

  1. The object has been created on the native device and is not yet synchronized with the server;
  2. The object has been created on the native device and has been synchronized with the server;
  3. The object has been created on the server and has been synchronized to the device.

Hence, it matters where the object has been created and if it has been synchronized.

  • An object created in native will have a (temporary) native object GUID, example: GUID:id_phb_174
  • An object created on the server will have an object GUID, example: 28991922601364212 1
  • Once an object gets synchronized between the Native device and the server the object will get the server GUID

1. Created on Native, not synchronized

In this stage the GetGuid action will return the Native object GUID as the object not yet exists on the server and the database (server-side) is in control of generating these identifiers.

2. Created on Native, synchronized with server

After synchronizing the objects created with the server, the object now has a GUID generated by the database as well. This information is also synchronized to the device. However when you call the GetGuid JavaScript action you will still get the Native object identifier, not the server GUID. Why? It appears that Mendix keeps returning the Native GUIDs until the app restarts. 2

The object GUID would be the perfect candidate to pass as Microflow parameter — since its not not allowed3 to have a persistable entity as Microflow parameter when the Microflow is called through a Native Nanoflow —if it weren’t for the behaviour described above: you still get the Native GUID, even when the object has been synchronized. This can’t be used to retrieve the object server-side (in the Microflow).

Workaround: perform a before commit event on the entity. The before commit event will retrieve the GUID (JavaAction) for the object and store it on a separate attribute (e.g. _GUID) on the entity. This attribute will be safe to use as a parameter in Microflows called from native Nanoflow, as the before commit action (all entity event handlers) are only executed on the server4 —and thus will set the correct GUID5— and you can check if this attribute has a value before calling the Microflow.

3. Created on server, synchronized with device

Objects created on the server will have a GUID like 28991922601364212, when these get synchronized to the native device the GetGuid will always return this GUID.


  1. The Object GUIDs in the Mendix database consist of two elements the entity and a sequencer, combined into a single identifier, but that is a topic for another day ↩︎

  2. It doesn’t depend on the type of data synchronization, but on whether the app / database is reloaded (it needs further investigation to determine when these changes are actually applied) but I’ve seen it happen after device restart and forced stop of the app ↩︎

  3. Displayed as error CE6897 Parameter 'MyFirstModule.Entity' is a persistable entity, which is not allowed in a microflow called from a nanoflow on pages that are accessible through a native profile. ↩︎

  4. Objects created from the native device to the server will trigger the commit event handlers during the synchronization process ↩︎

  5. It doesn’t need to be the GUID, any identifier (even one generated on the Native device) could be used to communicate between the Native device (Nanoflow) and the server (Microflow) which object needs to be used ↩︎