cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Connected loaddata/savedata

Using Excel on OD4B as a data source (but I imagine it doesn't matter as it pertains to my question).  In the OnStart or OnVisible attribute for the home screen, I easily can add an expression like 

 

If(Connection.connected, set(varOnline,true),set(varOnline, false)

 

I can also proceed to do either a ClearCollect() or a LoadData, but my question becomes:

 

If the device is not online, i.e., connected, the first time the app runs, how can PowerApps do a LoadData to get the Excel data to use?  Would that not have to have been saved on the device from some prior time?

 

More generally, I have these related questions:

 

  1.  If the device may not be online when the app runs, is that a caution not to rely on  a datasource that could be updated by other users at any time?  Say, for example, the app references a list of contacts where it can add, modify or delete items.  Would you not want that to run in a not connected world for concern about not having or delivering "current" data?
  2. Assume the device is connected the first time the app runs.  Should it still do a savedata to create a local copy of items it will need to load subsequently if it is not onlline?  For example, if an Excel file holds a static reference table that is used for calculations and/or display, does it have to be saved for use when the device is not connected?  And is there a way to "know" that the data has not yet been saved locally?
  3. Suppose a device is not connected and the app runs but has some data that needs to be added to what is normally an online datasource (say a SP list or even an Excel file).  The app runs and stores that data locally via savedata.  On a subsequent run of the app, the device is now connected.  How can the app "know" to load the data and do Patch(), etc. to move that locally save data to online sources?  Use CountRows() or CountIf() or some other means?

 

Thanks in advance for your answers which I hope are forthcoming.

2 REPLIES 2
Community Support Team
Community Support Team

Re: Connected loaddata/savedata

HI @lmheimendinger ,

Could you please share a bit more about your scenario?

 

Based on the issue that you mentioned, I think you have something misunderstanding on Offline app in PowerApps.

For your first question, if your device is not online (not connected) when you run your app first time, you could not load any data from your Excel table (in your OD4B folder) into your app. The LoadData() function is used to load a cached data into a existing Collection, if your device is not online (not connected) when you run your app first time, there is no data would be loaded within your app.

 

For your second question, if the device is connected the first time the app runs, you need to do a savedata to create a local copy of items for loading subsequently if it is not online. If your device is connected the first time the app runs, you must save the data from your Excel table into local cached data (using SaveData() function).

More details about creating an Offline app within PowerApps, please check the following blog:

https://powerapps.microsoft.com/es-es/blog/build-offline-apps-with-new-powerapps-capabilities/

 

For your third question, do you want to know how the app "knows" to load data and do Patch? Actually, a Timer control could achieve your needs. You could add a Timer control within your app, set the Duration property to 1000, and set the AutoStart property and Repeat property to true, set the OnTimerEnd property to following:

 If(
Connection.Connected, /* Check if the device is online/connected every second (1s) */ ForAll(LocalTweetsToPost, Twitter.Tweet("", {tweetText: tweetText})); Clear(LocalTweetsToPost); Collect(LocalTweetsToPost, {tweetText: NewTweetTextBox.Text}); SaveData(LocalTweetsToPost, "LocalTweetsToPost"); UpdateContext({statusText: "Online data"}) )

Above Timer control would check if the device is online/connected every second (1s), if yes, save local cached data to cloud data source (e.g. Excel table in your OD4B). Please check the above blog I mentioned for more details.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Re: Connected loaddata/savedata

Sorry I have been on the road and not been able to respond.  First, thanks a bunch.  Second, no, I didn't have the wrong idea but was instead asking so as not to make a stupid assumption.

 

I imagine that when the app runs and the device is offline, it should do something like:

 

loaddata()

If(IsBlank(loadeddata),"have to be online first time","continue with processing"))

 

I hadn't thought about the timer; if I am correct, as long as the devivce is on, it willl keep trying for the interval in the hopes that eventually it will be online.  This does seem preferable to just checking when the app runs as it may (although unlikely) be a while before the app is used on the device again.

 

I'll check back when I have had a chance to fiddle with the app next week.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 206 members 4,597 guests
Please welcome our newest community members: