Hello everyone! How should I properly update an aggregate based on input parameters to avoid unnecessary server requests? Should this be done during screen initialization, or is there a better approach?
If I put it in OnInitialize it gives the message:
'OnInitialize' accesses Aggregates or Data Actions, but the data might not be available at this time. To avoid inconsistencies, use the OnAfterFetch of the Aggregate or Data Action instead.
Hello,
It is not recommended to use any database or server side action into OnInitialize because this may case performance issue and incorrect behavior or exception in case data is not ready.
As per OutSystems tooltip of OnInitialize event this action is running early before navigating to screen and it can be used for initializing local variables.
You can use aggregates or Data actions with value of fetch property At Start then you can call onAfterFetch to handle retrieved data or any logic.
Also in case input parameters can be changed by the user so you can refresh your aggregate into OnChange action of your input field
Hello ,Follow below step.
1.If you are using web block then run your aggregate onparameterchange and add filter likeif(inputparam="" or entity.attribute=inputparam)
2.If you are using aggregate on same screen then on where input value got change at that event just refresh your aggregate(make sure your aggregate should be on demand)
Hope this will help you.
Hi @_N_C_ ,To update the aggregate you need to make sure you have the data in it.When an aggregate finishes fetching data it triggers an event OnAfterFetch (you can find it on the Aggregates property page.).Add an event handler (a client action) to this event and perform needed updates.
In you question you talked about minimizing server requests, could it be that you want to update DB based on input parameters? if it so then update data first in DB using server action with relevant input parameters and then refresh the aggregate which is set to execute on demand that fetches the updated data.