What is the current object of a context?

0
I am creating a piece of Java code that uses the IContext.getCurrentIdentifier() method (documentation here). I use this method in a before commit event handler. It returns the expected identifier and the Java code does what it is supposed to do. However, I am wondering, what is the 'current object' the documentation refers to? More generally, why would a context only have one object? Furthermore, will this always work, i.e. will this method always return the identifier of the object triggering the before commit microflow?
asked
1 answers
2

I think (not sure) that the IContext.getCurrentIdentifier() method is now just legacy. Bit of history:

Before Mendix had microflows, every action had to be a Java action. But because there were no microflows, there also wasn't a "call Java action" activity where you could pass parameters to the action. This meant that Java actions did no have any parameters, but had to "find" this information in the context.

I think there were 4 ways to call a Java action:

  • From an event handler on the entity (e.g. before commit), in which case the current object would be the object on which the event triggered.
  • From a button on a data grid, in which case the current object would be the selected object.
  • From a button/event on a data view, in which case the current object would be the same as "[%CurrentObject%]".
  • From a scheduled event, in which case there wouldn't be a current object.

Then there was also the IContext.getContextObjects() method, which would return all objects in the context (including the current object). In those older Mendix versions the context mechanism was basically always enabled with no way to turn it off (now it's the apply context setting on forms which is off by default). The contents of this context (which could contain anything, depending on the way the user navigated the application up until that point) was returned by this method, which you then had search for yourself (usually you'd search for a certain object type).

As Michel mentioned and the Mendix documentation recommends, there are now far better ways to achieve this (like parametrised microflow calls, including the options to pass any object), so I wouldn't use these old methods.

answered