How can I pass a parameter to microflow to indicate the field from which the onChange event gets triggered?

How can I pass a parameter to microflow to indicate the field from which the onChange event gets triggered? For instance: I have three different fields(cells) which triggers their own microflows on “onChange” event. I want to create one generic microflow and call these three onChange microflows inside it based on the field from which onChange microflow gets triggered. (This might look like a weird behavior, but I want to extend this feature and build a generic validation framework)
2 answers

When using on change microflows, you can only pass the whole object. In Mendix it is not possible to determine which attribute of the object has changed.

The workarounds that I can think of are:

  1. Us seperate on change microflows per field. Then in you generic validation flow, add these microflows as subflows so that you reuse your code
  2. Validate all the attributes even if they have not changed. Which causes extra overhead, but does limit the amount of microflows you need.

There are a couple of Java actions in the Community Commons module that might help you: GetOriginalValueAsString and memberHasChanged. This way you can check whether a single attribute has changed. You can also do this by retrieving the existing record from the database in your microflow, and comparing the values from the original object to the one passed to your microflow (which is the unsaved updated version). This will work OK if you are only checking a small number of attributes, but would become unwieldy if there are many to check, or if you change more than one attribute between commits.

Having separate OnChange microflows would be easier to maintain and more scalable. Remember, that if much of the microflow actions are identical, you can call a sub-microflow containing these actions.

One other possibility using this approach is to have separate on-change microflows for each attribute, but the microflow called simply sets a string variable with the hard-coded attribute name, then calls your generic on-change microflow passing the string value as a parameter so you can use it in your logic.