Best way to get DB data on mobile app

Could you tell me the best way to get DB data on mobile app.

I want to show personal data getting by Rest API from other system in mobile app.

All user needs to log on. Screen shows personal data from Local Entity.Local Entity gets personal data from DB Entity using filter by logon user name(User_GetName()).


I set ClientAction to get personal data for DB Entity into Local Entity.
And I set ClientAction to Local Entity's  "On After Fetch".
I got right Screen, but it takes few seconds to show up, sometimes it shows only null data.


What is the best way to get some Local data from DB at mobile app?
I tried to set it on ClientAction at Splash, but Screen showed null data when user logged on for the first time.It doesn't through Splash after first log on, is it?


Best Regards.

Hello Yumiko,


It seems that you're doing your sync (calling the server database and copying stuff to the local storage) during the screen load?

This should happen before - check your Offline data sync settings and make sure you're syncing there. The local storage should be available before you start loading the screen. The access to this storage should be pretty much instantaneous when changing screens.

Yumiko Ueyama wrote:

Could you tell me the best way to get DB data on mobile app.

I want to show personal data getting by Rest API from other system in mobile app.

All user needs to log on. Screen shows personal data from Local Entity.Local Entity gets personal data from DB Entity using filter by logon user name(User_GetName()).


I set ClientAction to get personal data for DB Entity into Local Entity.
And I set ClientAction to Local Entity's  "On After Fetch".
I got right Screen, but it takes few seconds to show up, sometimes it shows only null data.


What is the best way to get some Local data from DB at mobile app?
I tried to set it on ClientAction at Splash, but Screen showed null data when user logged on for the first time.It doesn't through Splash after first log on, is it?


Best Regards.

Hi


Please follow the below link.Best way to achieve what you want AFAIK. 

https://www.outsystems.com/learn/lesson/782/local-storage
https://www.outsystems.com/learn/lesson/783/local-storage-exercise


Mariano Picco wrote:

Hello Yumiko,


It seems that you're doing your sync (calling the server database and copying stuff to the local storage) during the screen load?

This should happen before - check your Offline data sync settings and make sure you're syncing there. The local storage should be available before you start loading the screen. The access to this storage should be pretty much instantaneous when changing screens.

Thanks your reply!


I might make mistake setting mobile app.
Could you check my way?

I set Local Entity to use "Add Entity from Database".And I set "Create Action to Sync data(Read-only)" at Client Action.Then I set this "on after fetch" at  Screen aggregate.
Is this right way?

If this is OK, please tell me the point of check.

Salman Ansari wrote:

Hi


Please follow the below link.Best way to achieve what you want AFAIK. 

https://www.outsystems.com/learn/lesson/782/local-storage
https://www.outsystems.com/learn/lesson/783/local-storage-exercise


Thanks your reply.


I'll try to check link.Thank you.

Solution

Yumiko Ueyama wrote:

Mariano Picco wrote:

Hello Yumiko,


It seems that you're doing your sync (calling the server database and copying stuff to the local storage) during the screen load?

This should happen before - check your Offline data sync settings and make sure you're syncing there. The local storage should be available before you start loading the screen. The access to this storage should be pretty much instantaneous when changing screens.

Thanks your reply!


I might make mistake setting mobile app.
Could you check my way?

I set Local Entity to use "Add Entity from Database".And I set "Create Action to Sync data(Read-only)" at Client Action.Then I set this "on after fetch" at  Screen aggregate.
Is this right way?

If this is OK, please tell me the point of check.

I will agree with Salman and advise you to check the data sync parts of the tutorials again. 

Basically your "Action to sync data" should go inside the OfflineDataSync action. This action is called whenever the app needs to fetch server-side data and update its local storage, depending on what comes back. 

When this action runs is up to each developer. Under your logic tab, you'll find a OfflineDataSyncConfiguration action which has several assign nodes inside it. You can go through each one, read the description, and set it to true/false depending on when your app should trigger the offline data sync action.

Or you can trigger it manually, by calling TriggerOfflineDataSync somewhere. 

Remember depending on how much data you're pulling this can be almost instantaneous or take several seconds to complete, so it's not advisable to add this action in the middle of screen loads and specially not screens which depend on the data to be up-to-date to function correctly.


Basically, your local storage should be all synced up and ready to go before hand, not being synced during screen initialising. 


Solution

Mariano Picco wrote:

Yumiko Ueyama wrote:

Mariano Picco wrote:

Hello Yumiko,


It seems that you're doing your sync (calling the server database and copying stuff to the local storage) during the screen load?

This should happen before - check your Offline data sync settings and make sure you're syncing there. The local storage should be available before you start loading the screen. The access to this storage should be pretty much instantaneous when changing screens.

Thanks your reply!


I might make mistake setting mobile app.
Could you check my way?

I set Local Entity to use "Add Entity from Database".And I set "Create Action to Sync data(Read-only)" at Client Action.Then I set this "on after fetch" at  Screen aggregate.
Is this right way?

If this is OK, please tell me the point of check.

I will agree with Salman and advise you to check the data sync parts of the tutorials again. 

Basically your "Action to sync data" should go inside the OfflineDataSync action. This action is called whenever the app needs to fetch server-side data and update its local storage, depending on what comes back. 

When this action runs is up to each developer. Under your logic tab, you'll find a OfflineDataSyncConfiguration action which has several assign nodes inside it. You can go through each one, read the description, and set it to true/false depending on when your app should trigger the offline data sync action.

Or you can trigger it manually, by calling TriggerOfflineDataSync somewhere. 

Remember depending on how much data you're pulling this can be almost instantaneous or take several seconds to complete, so it's not advisable to add this action in the middle of screen loads and specially not screens which depend on the data to be up-to-date to function correctly.


Basically, your local storage should be all synced up and ready to go before hand, not being synced during screen initialising. 


Thanks your help.

I checked the data sync parts. I figured out about my question.

And I got a new question.

Which is processed first between "Offline Data Sync" and "Screen's Local Aggregate" if I set "Sync on Online" is true in Offline Data Sync Configuration?

I want completely to set the order so that "OfflineDataSync" is followed by "Screen's Local Aggregate" and other LocalAction.  


Could you give me advice again?

Best Regards.


Yumiko Ueyama wrote:

Thanks your help.

I checked the data sync parts. I figured out about my question.

And I got a new question.

Which is processed first between "Offline Data Sync" and "Screen's Local Aggregate" if I set "Sync on Online" is true in Offline Data Sync Configuration?

I want completely to set the order so that "OfflineDataSync" is followed by "Screen's Local Aggregate" and other LocalAction.  


Could you give me advice again?

Best Regards.

When you set Sync on Online it tells the app that, if it was offline and became online, to start a data sync.

The thing about mobile data sync actions - they're asynchronous. Requests are sent out, and there's no telling which one will return first. 

If you want your Offline Data Sync to run, you must trigger it somehow. I advise against triggering it every time you come into a screen. It could get very laggy depending on how you're doing the sync.

But if you must, then you gotta trigger it somehow (like on the OnReady event of the screen)

Then, you can actually react to the sync finishing, because it triggers an event for which you can define a handler. 

Go to your screen's Widget Tree, select the layout WebBlock and set it here:


You mention you want your data to ONLY be fetched AFTER the sync completes. So, your data should be set to fetch Only On Demand, and your OnSyncCompleteHandler should be something like this:


The Refresh action here tells the Data action to run. It shows here a server type aggregate but it will work the same with local storage.


Hope this helps