Data from client action reactive
Question

Hi

Im using reactive. I need to fetch data for my screen. This data is fetched and returned from a client action. I dont have an aggregate, so i cant use the on after fetch 

How and when do i call this client action? So i can display it on my screen.

Thanks.

Bashnie

Hi Bash,

where is that data located? Database or Local Storage?

I will assume you use an aggregate inside a client action to get data from Local Storage. 

You have 2 options. Move the aggregate inside the client action to a screen aggregate and use it in the screen by calling it's result.

Another option is to assign the current result of the aggregate inside the client action to a local variable of its type. But for this happen, you need to trigger the client action with a button or link in the screen.

Regards

Hi.

Data is indeed fetched from local storage by using an aggregate. The client action gets the data assigned as output.

The data should be available when the screens opens for the first time. So a button or link is not an option unfortunately.

The specific set of data returned by the aggregate is used in multiple locations. To avond duplicate code I dont like to make it a screen aggregate on all those places

Bash nie 

Hi Bash,

call that client action in "OnInitialize" event handler action of that page. create local variable of same type as client action output variable and at the end of onlinitialize event handler action assign the output of client action to local variable. now you can bind that local variable on screen anywhere.

attached oml contains simple example for your understanding.

Demo8.oml

Hi, thanks think this is what i needed.

Now i'm wondering. Do I than also need to call the client action again in the onparameterschanged event? (Or trigger OnInitialize client action in OnParametersChanged)

Just like when the platform suggests when you have an aggregate with an input parameter from the screen.

It's a bad practice to call client actions that use aggregates or aggregates directly on the OnInitialize event. It will only load your screen after the data is fetched.

It is stated  right there:


The right option for you is to use a Fetch Data from Local Storage on your screen.


But this means that those local aggregates cannot be centralized and that there will be duplicate code if im not mistaken. 

Call the client action in the OnReady event. Make sure you control it to be called only once, the first time it runs.

The data is fetched from the entity onStart and the OnAfterFetch client action refreshes the aggregate for display. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.