Calculated Attributes - Refresh Fequency

0
Hi I’m using a calculated attribute in a child entity for conditional visibility that’s actually based on an attribute in a parent entity (which can’t be directly accessed by visibility rule in the child or pages based on the child)... Data Model Client (entity) - ClientType (enumeration attribute with values Child, Parent, Other) ClientAssessments (entity) - ClientTypeCalc (calculated based on ClientType in Client entity above). This calculated attrib enables visibility controls in UI elements based on ClientAssessment.   Use Case pagClient enables ClientType to be updated. In practice, once a ClientType is set, it won’t change, but I have to allow for data entry errors. - pagClient has a data grid for ClientAssessment, which is used to edit selected ClientAssessments by opening pagAssessment. pagAssessment has n tabs of various types of assessments, where each tab’s visibility needs to be controlled by ClientTypeCalc. 1, 2 or 3 of the ClientType values can satisfy the visibility requirements in order to display any given tab. For example, Assessment A may be used for just a child, whereas Assessment B may be used for both a child and a parent.   Original Issue  This design works fine, unless I change ClientType in pagClient. ClientTypeCalc does not refresh unless I exit and restart the app.   Current Solution (based on suggestions below) When I open pagAssessment, I’ve added an on-click-edit microflow that commits the selected ClientAssessment and then opens pagAssessment. This seems to trigger a refresh (noted in Mike’s and Tim’s answers), so the ClientTypeCalc attribute is now correctly updated.   Question I can’t get around the business requirement to manage visibility based on attributes that are not in the current object. My current solution is spreading the logic across a calculated field and a micrflow, which isn’t the most elegant solution.  - Is there a better way to handle this requirement? - does anyone know if Mendix is planning to add more event handlers, esp on UI objects (e.g. on-open events)? while an on-click-edit event may seem like it’s the equivalent of an on-open, the problem with the current solution is that the child page (pagAssessment) can be called from multiple other pages.  
asked
2 answers
1

Calculated attributes refresh each time the entity containing them is retrieved from the database (which happens when a page is opened, when an entity is committed with page refresh, and in many other instances).  The reason the construct you describe above doesn’t work is because Entity B is not being refreshed (re-retrieved from the database) when you change entity A.

I am not sure what your use case is, but a couple of thoughts that may be helpful:

  • you can perform actions prior to opening a page.  Create a microflow that does everything you want to do prior to opening a page, then have the last action be an open page action.  Then instead of opening a page directly, open it by calling the microflow you created.
  • controlling visibility via the scenario you’ve outline is going to be difficult.  For instance, assume you and I are both users of the app, you have a page open that displays entity B and I have one open that displays entity A.  If I update entity A, your tab visibility won’t refresh until you refresh your page (i.e. reload it) or navigate away from it and open it again.  There are some ways to force that refresh on a periodic basis (microflow timer widget in the appstore, for instance), but these are not ideal

Perhaps if you could describe your use case in more detail, the community could suggest some ways to accomplish what you need to.

Hope that helps,

Mike

answered
0

Refresh rate is upon reshowing the calculated attribute in a UI

Well, the After some experimenting, the calculated attribute stays fixed  when:

  • ObjectA gets modified without an ACo-event changing B and B is shown in plain datagrid (showing all available records)
  • Page refresh, tabbing back and forth, datagrid-paging back and forth do not trigger recalculation.

This is not as expected nore described in docs.mendix.com

It does get recalculated after:

  • ObjectB gets changed itself
  • ObjectA gets modified and ACo_A changes B: shows on page refresh, or on switching tabs, or on datagrid-paging forward and backward
  • ObjectA gets modified but without ACo_A changes B: shows on page refresh, or on switching tabs, or on datagrid-paging forward and backward???@#@This puzzled me because I saw first the calculated attribute did not get updated….

So now I am back where I started and recalculation is working ok. But why was it not the first time?

Maybe you just ran into a updating-calculated-attribute-bug and if you can reproduce it, report it at support.mendix.com

Response to FWIW/OTOH: Mendix does lazy-update B-attrib upon changing A, which does not impact preformance since only upon refreshing the page showing B does trigger the Cal_B_AttribB-microflow and only for this particular attrib. So the UI's have a listener. That mechanism seems to be in place but not entirely functioning.

 

answered