Storing value in local variable OnInitialize to be used by other aggregates

Hi all,

I have a question. This is about mobile development. On page initialization, I want to run a query to get the User's accumulated points, store it in a variable, and then this value will be used by different aggregates on page load to help page performance. 

I have added a Local Variable and Assign its value OnInitialize with the aggregate but it is not assigning correctly. It still shows 0 when I try to display it on the page. I tested the aggregate it's returning a correct value but somehow it's either not assigning during OnInitialize or it's assigned after the page finishes loading already.

Any thoughts? Thanks!


Hi Herman,

There are several problems to your approach.

1. OnInitialize action is run before any aggregate is done, and

2. Since the server aggregates run asynchronously, and include a round trip to the server, the data will only be available client-side, much after the screen is displayed.

If you see this article in the documentation, you'll understand that your current approach is not possible.

How can you make it work?

a. I noticed that you have 3 server aggregates. If they are related, I would suggest you to have instead a DataAction what will execute the 3 aggregates inside (1 round-trip to the server instead of 3)

b. Pre-load that information upon login, in a client variable and keep updating it, upon usage, but then you can pass that value to the server aggregates.

Let me know, if this helps you out.




Thank you for pointing that out! I revisited the link you sent and the video and figure out how to pass this variable around. On my 2nd page screen aggregate filters I cannot use Client Variables I have to use Input Parameter so here is what I do:

- Declare a Point as Client Variable

- Home screen on Render I assign Point to a value returned from aggregate

- On the link to the 2nd page I assign the Input Parameter value to be Point.

- Now on 2nd page aggregate filters I can use the Input Parameter.

Is that a good approach? 

I am still having page performance issue and looking into replacing it with DataAction. But thanks for pointing that out! I had been spending hours trying to use CV, static entity, input param etc so that I don't have to re-calculate points on each screen.


Hi Herman,

Glad that I could help.

I would suggest for you to really use the DataAction, because then all inside it is running server side, so you can obtain the points value and use them.

Sorry about the suggestion of using client variables, I've noticed that you'd need to have client action that would call a server action, and only in this situation you could pass a parameter that would be the value stored in the Client Variable.

Hope this helps you out,