cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Offline app - LoadData Function Indicating File Doesn't Already Exist

Hello,

 

I am trying to build a simple mechanism to my app to extend its use offline.

 

What I want to do: OnStart of the app, if there is connection, I want to save four tables to four different collections and then save those collections to my local cache. If there is no connection, I want to load those four tables into the collections.

 

What I have:

If(
// Check for connection
Connection.Connected,
// Connection - Save data to collections
ClearCollect(CollectionOne, TableOne);
ClearCollect(CollectionTwo, TableTwo);
ClearCollect(CollectionThree, TableThree);
ClearCollect(CollectionFour, TableFour);
// Save tables to local cache
SaveData(TableOne, "One");
SaveData(TableTwo, "Two");
SaveData(TableThree, "Three");
SaveData(TableFour, "Four"),
// No Connection - Retreive data from local cache & save in collections
LoadData(CollectionOne, "One", false);
LoadData(CollectionTwo, "Two", false);
LoadData(CollectionThree, "Three", false);
LoadData(CollectionFour, "Four", false);

);

 

What is happening:

I keep getting this error as if the name of the file does not exist: "There was a problem loading your data".

However, as you can see all names ("One", "Two", "Three", "Four") are matching. Is there something I am doing wrong when saving the data (SaveData)?

 

On a side note, the documentation for SaveData is not consistent/clear.

The online microsoft docs at https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-savedata-loaddata say: SaveDataCollectionName ) - Collection - Required. Collection to be stored or loaded.

In Power Apps, SaveData( source, name) - Source: A table whose contents will be saved.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @Anonymous ,

I have been using this function for about two years without issue and suggest the following:-

  • SaveData from the Collection - you have already queried the data, so no need to go back to it again when you have it in the app.
  • Use the true parameter on LoadData to ignore the command if the device has not yet configured the structure with the SaveData command. Not a big deal, but it will error if the phone app is opened offline first.
  • I may be stating the obvious, but you cannot test this on a PC - it has to be on a mobile device.
If(
   Connection.Connected,
   ClearCollect(CollectionOne, TableOne);
   ClearCollect(CollectionTwo, TableTwo);
   ClearCollect(CollectionThree, TableThree);
   ClearCollect(CollectionFour, TableFour);
   SaveData(CollectionOne, "One");
   SaveData(CollectionTwo, "Two");
   SaveData(CollectionThree, "Three");
   SaveData(CollectionFour, "Four"),
   LoadData(CollectionOne, "One", true);
   LoadData(CollectionTwo, "Two", true);
   LoadData(CollectionThree, "Three", true);
   LoadData(CollectionFour, "Four", true);
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

13 REPLIES 13
WarrenBelz
Super User
Super User

Hi @Anonymous ,

I have been using this function for about two years without issue and suggest the following:-

  • SaveData from the Collection - you have already queried the data, so no need to go back to it again when you have it in the app.
  • Use the true parameter on LoadData to ignore the command if the device has not yet configured the structure with the SaveData command. Not a big deal, but it will error if the phone app is opened offline first.
  • I may be stating the obvious, but you cannot test this on a PC - it has to be on a mobile device.
If(
   Connection.Connected,
   ClearCollect(CollectionOne, TableOne);
   ClearCollect(CollectionTwo, TableTwo);
   ClearCollect(CollectionThree, TableThree);
   ClearCollect(CollectionFour, TableFour);
   SaveData(CollectionOne, "One");
   SaveData(CollectionTwo, "Two");
   SaveData(CollectionThree, "Three");
   SaveData(CollectionFour, "Four"),
   LoadData(CollectionOne, "One", true);
   LoadData(CollectionTwo, "Two", true);
   LoadData(CollectionThree, "Three", true);
   LoadData(CollectionFour, "Four", true);
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

RebekahWang
Frequent Visitor

I have the same issue. Same code follow the pattern to savedata once online, and loaddata when offline. The code works on one app, but in another app, the cache file is not created. Has anyone experienced the same issue and found a solution?

 

Hi @RebekahWang ,

One clarification here - are you trying to get the data saved in one app to load in another ? If so, this will not work as they are actually different files behind the scenes.

Hi WarrenBelz, 

I am running the same code (collect,savedata,loaddata) on two separate apps, which will savedata to each app's local cache(same cache name but I think that should be fine, since the scope is own app). The first app can get the data from its cache, but the second app does not have any data in the cache.  

Hi @RebekahWang ,

I am not sure how to respond further - the same code should work in any app.

Thank you @WarrenBelz , and I am using the first app to test the offline function code, and the second app is an existing app which are going to have the offline function using the verified offline code in the first app.  

@RebekahWang ,

I assume you are testing this on a mobile device, or on the Windows App with this turned on

WarrenBelz_0-1653557311089.png

 

I tested this on Mobile app and the feature you highlighted is on definitely. 

RebekahWang
Frequent Visitor

I am not sure whether other app setting features will affect the cache. Since I turned on the following two features once, and tested the second app then it shows the data from cache, after I turned off/on these two features again, it never get the cache data any more. Seems some issue with app settings, but could not reproduce now.

 

RebekahWang_0-1653557785081.png

 

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,171)