Best practices calculated attributes

1
I have a simple example where I want to show the age of an Employee. I can easily add a calculated attribute to the Employee entity and let a microflow determine the age, but I understood this microflow will be triggered each time the Employee entity is retrieved somewhere. Although this is not a very heavy operation I still want to know if there are better ways to use attributes like this. We are also planning to use more calculated attributes like informalName, formalName, displayName etc. I was wondering whether moving the calculated attributes to a separate entity would prevent the microflows from triggering each time. Would it be wise to move them to an ExtendedEmployee entity which would be linked as 1-on-1 or as a specialisation? Or are there better ways to display calculated attributes like age etc?
asked
4 answers
6

1. Try to recalculate them when needed (for age can be checked once a day for your accounts) and leave the attribute static.

2. With events (before/after commit) calculate the attribute

3.  In your commit microflow

4. An extended entity (with 1-1) is a good solution when the calculated attrribute uses the context of the current user. Otherwise see 1.

answered
2

If you need to be able to search on the age attribute, then having a 'static' attribute which is updated through workflow, perhaps by a scheduled event is the way to go.

If you don't need the attribute, except to display the current age in a display page, then you could use the CustomString widget to calculate the value and display it.  The microflow to calculate the value would only be triggered on the pages displaying the widget and you don't need a database attribute at all.

answered
0

What I do is determine when the calculation happens. Often you will see that this either happens when a change is committed or on a regular basis (yearly, dayly, etc.). In the first case, go for an event handler that sets the value. In the second case, go for a scheduled event. For example, you can check daily whose birthday is today. For those people, calculate or add one to their age.

answered
0

What i do is to Use a Static Attribute and then perform change object when required or run a schedule event every day.

answered