How to create a calculated attribute (equivalent to calculated field in Excel table)

0
I don’t know why this seems so counter-intuitive to me. I guess I’m used to the logical flows in Microsoft Excel. I’m brand new to Mendix. I have an entity. The entity has a string attribute called ObjectName and a string entity called ObjectSerialNumber. I want to create a calculated attribute that will result in concatenation of ObjectName, space-dash-space, last 4 digits of Object SerialNumber…. so “Widget – 1234”. The calculated attribute should be formulated once the ObjectName and ObjectSerialNumber are committed.   Do I do this in Mendix Studio? Mendix Studio Pro? Does it have to happen with a microflow? If so, what does that microflow look like?
asked
1 answers
1

Jason,

To accomplish this in Mendix, add an attribute to your entity to hold the calculated attribute.  Then, you can either:

  • set the attribute’s value to be calculated (instead of stored) in the properties page for your attribute.  Create a microflow that determines (in a variable or in the expression of the end event of the microflow), the combinec value.  The microflow should return the combined value.
  • set the attribute’s value to stored.  Then create a microflow that calculates and updates the attributes value.  Call this microflow as an event handler on the entity – if you choose an after commit event, make sure your microflow commits without events (to prevent an endless loop and out of memory condition).

If you use the first option, keep in mind that Mendix will recalculate the attirbute value every time an object is retrieved from that entity.  If the entity will have more than a handful of objects, this is probably not the option you want to use.  

The second option will only be executed when changes to an object are committed to the database.

Hope that helps,

Mike

 

answered