Coherence Suggestion 'MyClientAction' accesses Aggregates or Data Actions..."

I'm developing a mobile that needs to read data from local storage and make an assignment to a local variable which will later be used to fetch data from a database. I have this structure in my Client Action flow:


Start

Aggregate (Local storage is read here)

Assign property from aggregate to local variable

Use local variable as parameter in a Run Server Action to fetch data from a database.

End


Under the Interface tab, the Screen that uses the client action is underlined and when I hover over it, I get this message:

"Coherence Suggestion
'MyClientAction' 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."

I believe I understand what this means as I can see that when running this in the debugger, I don't always get the expected data from the aggregate. (Asynchronous behavior?)


So how can I resolve this issue?


Solution

Hi Lorenzo,

You are right about the async behavior of data loading in OutSystems mobile. All data fetch actions run in parallel after the initialize event.

(Screenshot taken from: https://success.outsystems.com/Documentation/11/Developing_an_Application/Implement_Application_Logic/Screen_and_Block_Lifecycle_Events)

And the data from the aggregate may not be available on the first render of the application screen. As and when data fetch is complete, the screen re-renders (as mobile apps use react framework for UI). Hence it is advised to use the On After Fetch event (you have to write the event handler code yourself) if you wish to ensure the data availability from aggregate before using it.


Hope this helps.


Regards,

Saugat


Solution

Saugat Biswas wrote:

Hi Lorenzo,

You are right about the async behavior of data loading in OutSystems mobile. All data fetch actions run in parallel after the initialize event.

(Screenshot taken from: https://success.outsystems.com/Documentation/11/Developing_an_Application/Implement_Application_Logic/Screen_and_Block_Lifecycle_Events)

And the data from the aggregate may not be available on the first render of the application screen. As and when data fetch is complete, the screen re-renders (as mobile apps use react framework for UI). Hence it is advised to use the On After Fetch event (you have to write the event handler code yourself) if you wish to ensure the data availability from aggregate before using it.


Hope this helps.


Regards,

Saugat



Thanks for the reply. But if I remove the aggregate from my flow, I still have the error. Also, my aggregate does have have a onAfterFetch option in its context menu. So what do I do? Sorry, very new to Outsystems.

Hi Lorenzo,

Basically, you need to add your aggregate to your screen and run it asynchronously. To do so, just right click in your screen and choose the option Fetch Data From Local Storage.
You will have something like this:


Then, in the properties of your Aggregate, you'll find an event called On After Fetch. This event will run when the fetch is completed.


Now, you should define a client action and assign it to this event. This action will run the logic after the fetch is done. For instance, let's call the action OnAfterFetchGetLocalStorage. Just assign it to the On After Fetch event in the aggregate and you will guarantee that the data will be fully available at this time.


Just implement the logic that you want in your OnAfterFetchGetLocalStorage actionwhich is the assign from the local storage to a local variable and use it as a parameter in the server action.


Let me know if you managed to do it.

Hope it helps.


Rui Barradas

Thanks Rui, for the screenshots. 


Lorenzo, Hope the details provided by Rui helps you resolve your queries. Do let us know.


Regards,

Saugat

Saugat Biswas wrote:

Thanks Rui, for the screenshots. 


Lorenzo, Hope the details provided by Rui helps you resolve your queries. Do let us know.


Regards,

Saugat


Yes, these answers helped. I have it working now.