Consume service action in OnInitialize.
Application Type
Reactive

Hi,

I need to consume the service action to display the data when the page get load.

could you please help me with the best approach.

consumed in OnInitialize  but getting the performance warning.


Thanks

Rajendra Singh

mvp_badge
MVP
Solution


Don't use the OnInitiize as a replacement of the Preparation action of a traditional web app. They both have different purpose.

You should remove the logic from the OnInitialize action, as this is not the event to get data to display on your screen. 

The data needs to be fetched asynchronously via a data action in your situation. In the data action you can call the service action.

When the data fetch is completed the output of it is available to be renderd on screen. You can event add an action to the ondatafetched event of the data action if you need to act upon the event that all the data is fetched.

 The service action is by definition a reusable action.

Hello Rajendra, the link that Daniel posted explains the path you should follow step by step. 

If you did exactly how it is recommended on that guide and still have the warning, that's because you may have code on the OnInitialize action that can be placed on other client actions.

Assuming that you only have that service action there, just remove it from the OnInitialize flow. Then, the best practice is to create a data action, call the service action inside this data action and define the source of your list with the data action output you just created.

If you need the data immediately available when navigating to this screen, you should put the data action fetching the data 'At Start', otherwise, you can use the option 'On Demand'. 

Does this help you? 

Best Regards, 

Paulo Z

Thanks Paulo Zacarias,

Yes need the data immediately.

I have called the service action inside the data action, and removed the logic from OnInitialize.

now i am not getting any warring but the data is reflecting little late, means I can see the old values for some second even the fetch property of data action is at start.(as the logic is not written in OnInitialize)

*based on the output of the service action I need to enable or disable the link in the screen.


Thanks

Rajendra Singh



Hi Rajendra, you can define an 'empty state' display that will be shown until that data is being fetched. 

Define a local variable of type boolean that will control what to display before and after the data from your data action is fetched. Use the 'OnAfterFetch' of the data action to change the boolean variable, this way you will only show the updated value. 

For the 'empty state' display you can even use some cool animations like a spinner for instance. 

Hope this helps you. 

Best Regards, 

Paulo Z.


mvp_badge
MVP

There is no need to create a boolean local variable for that purpose.

Just use the IsDataFetched runtime property of the Data Action in order to toggle between the empty state and displaying the data whenever it is available.

Regards,

Nordin

You're right Nordin, in this case, the IsDataFetched suits the need. 

Best Regards, 

Paulo Z


Hi Nordin Ahdi,

Thanks a lot for your help, your solutions helped me to resolve my issue but not 100%.

because I have a webblocks and list into this page, i also need to  add this condition to toggle these, its working but not like a preparation.(first the page is getting load then based on the Boolean list and webblock, so for some seconds I can only see the page even i have used spinner to block the user to click on the page ).


Thanks

Rajendra Singh 



mvp_badge
MVP

Hi,

Use the fetch from other data action to call the service action.

For details see here.

Regards,

Daniel

Thanks Daniël Kuhlmann, but still  I am getting the warning-

'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.


My Requirement is create a reusable action in the producer espace which can be called in the multiple screen's of producer  so that we can display the data on initialize of the screen(without any warning)


Thank

Rajendra Singh

mvp_badge
MVP
Solution


Don't use the OnInitiize as a replacement of the Preparation action of a traditional web app. They both have different purpose.

You should remove the logic from the OnInitialize action, as this is not the event to get data to display on your screen. 

The data needs to be fetched asynchronously via a data action in your situation. In the data action you can call the service action.

When the data fetch is completed the output of it is available to be renderd on screen. You can event add an action to the ondatafetched event of the data action if you need to act upon the event that all the data is fetched.

 The service action is by definition a reusable action.

Hello Rajendra, the link that Daniel posted explains the path you should follow step by step. 

If you did exactly how it is recommended on that guide and still have the warning, that's because you may have code on the OnInitialize action that can be placed on other client actions.

Assuming that you only have that service action there, just remove it from the OnInitialize flow. Then, the best practice is to create a data action, call the service action inside this data action and define the source of your list with the data action output you just created.

If you need the data immediately available when navigating to this screen, you should put the data action fetching the data 'At Start', otherwise, you can use the option 'On Demand'. 

Does this help you? 

Best Regards, 

Paulo Z

Thanks Paulo Zacarias,

Yes need the data immediately.

I have called the service action inside the data action, and removed the logic from OnInitialize.

now i am not getting any warring but the data is reflecting little late, means I can see the old values for some second even the fetch property of data action is at start.(as the logic is not written in OnInitialize)

*based on the output of the service action I need to enable or disable the link in the screen.


Thanks

Rajendra Singh



Hi Rajendra, you can define an 'empty state' display that will be shown until that data is being fetched. 

Define a local variable of type boolean that will control what to display before and after the data from your data action is fetched. Use the 'OnAfterFetch' of the data action to change the boolean variable, this way you will only show the updated value. 

For the 'empty state' display you can even use some cool animations like a spinner for instance. 

Hope this helps you. 

Best Regards, 

Paulo Z.


mvp_badge
MVP

There is no need to create a boolean local variable for that purpose.

Just use the IsDataFetched runtime property of the Data Action in order to toggle between the empty state and displaying the data whenever it is available.

Regards,

Nordin

You're right Nordin, in this case, the IsDataFetched suits the need. 

Best Regards, 

Paulo Z


Hi Nordin Ahdi,

Thanks a lot for your help, your solutions helped me to resolve my issue but not 100%.

because I have a webblocks and list into this page, i also need to  add this condition to toggle these, its working but not like a preparation.(first the page is getting load then based on the Boolean list and webblock, so for some seconds I can only see the page even i have used spinner to block the user to click on the page ).


Thanks

Rajendra Singh 



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