You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Operators and identifiers](functions/operators.md)
28
28
*[Controls and their properties](reference-properties.md)
29
29
*[Data types](functions/data-types.md)
30
30
@@ -203,7 +203,7 @@ Other elements include:
203
203
204
204
**[Ln](functions/function-numericals.md)** – Returns the natural log.
205
205
206
-
**[LoadData](functions/function-savedata-loaddata.md)** – Loads a collection from Power Apps private storage.
206
+
**[LoadData](functions/function-savedata-loaddata.md)** – Loads a collection from a local device's storage.
207
207
208
208
**[Location](functions/signals.md)** – Returns your ___location as a map coordinate by using the Global Positioning System (GPS) and other information.
209
209
@@ -291,7 +291,7 @@ Other elements include:
291
291
**[RoundUp](functions/function-round.md)** – Rounds up to the smallest next number.
292
292
293
293
## S
294
-
**[SaveData](functions/function-savedata-loaddata.md)** – Saves a collection to Power Apps private storage.
294
+
**[SaveData](functions/function-savedata-loaddata.md)** – Saves a collection to a local device's storage.
295
295
296
296
**[Search](functions/function-filter-lookup.md)** – Finds records in a table that contain a string in one of their columns.
Copy file name to clipboardExpand all lines: powerapps-docs/maker/canvas-apps/functions/function-savedata-loaddata.md
+107-6Lines changed: 107 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ search.app:
15
15
- PowerApps
16
16
---
17
17
# SaveData and LoadData functions in Power Apps
18
-
Saves and re-loads a [collection](../working-with-data-sources.md#collections).
18
+
Saves and re-loads a [collection](../working-with-data-sources.md#collections) from a local device.
19
19
20
20
## Description
21
21
The **SaveData** function stores a collection for later use under a name.
@@ -28,21 +28,122 @@ You can't use these functions inside a browser, either when authoring the app in
28
28
29
29
These functions are limited by the amount of available app memory because they operate on an in-memory collection. Available memory can vary depending on the device and operating system, the memory that the Power Apps player uses, and the complexity of the app in terms of screens and controls. If you store more than a few megabytes of data, test your app with expected scenarios on the devices on which you expect the app to run. You should generally expect to have between 30 and 70 megabytes of available memory.
30
30
31
-
**LoadData** doesn't create the collection; the function only fills an existing collection. You must first create the collection with the correct [columns](../working-with-tables.md#columns) by using **[Collect](function-clear-collect-clearcollect.md)**. The loaded data will be appended to the collection; use the **[Clear](function-clear-collect-clearcollect.md)**function first if you want to start with an empty collection.
31
+
These functions depend on the collection being implicitly defined with the presence of a **[Collect](function-clear-collect-clearcollect.md)** or **[ClearCollect](function-clear-collect-clearcollect.md)** function call in any formula within your app. You do not actually need to call **Collect** or **ClearCollect** to load data into the collection in order to define it, which is the common case when using **LoadData**after a previous **SaveData**. All that is needed is the presence of these functions in a formula to implicitly define the structure of the collection. For more information see [creating and removing variables](../working-with-variables.md#create-and-remove-variables).
32
32
33
-
Storage is encrypted and in a private ___location on the local device, isolated from other users and other apps.
33
+
The loaded data will be appended to the collection. Use the **[Clear](function-clear-collect-clearcollect.md)** function before calling **LoadData** if you want to start with an empty collection.
34
+
35
+
The device's built in app sandbox facilities are used to isolate saved data from other apps. The device may also encrypt the data or you can use a mobile device management tool such as [Microsoft Intune](https://www.microsoft.com/en-us/microsoft-365/enterprise-mobility-security/microsoft-intune) to encrypt if desired.
**Collection* - Required. Collection to be stored or loaded.
39
41
**Name* - Required. Name of the storage. You must use the same name to save and load the same set of data. The name space isn't shared with other apps or users.
40
-
**IgnoreNonexistentFile* - Optional. Boolean (**true**/**false**) value that indicates whether **LoadData** function should display or ignore errors when it can't locate a matching file. If you specify **false**, errors will be displayed. If you specify **true**, errors will be ignored, which is useful for offline scenarios. **SaveData** may create a file if the device is offline (that is, if the **Connection.Connected** status is **false**).
42
+
**IgnoreNonexistentFile* - Optional. A Boolean value indicating what to do if the file does not already exist. Use *false* (default) to return an error and *true* to suppress the error.
41
43
42
44
## Examples
43
45
44
46
| Formula | Description | Result |
45
47
| --- | --- | --- |
46
-
|**If(Connection.Connected, ClearCollect(LocalTweets, Twitter.SearchTweet("PowerApps", {maxResults: 100})),LoadData(LocalTweets, "Tweets", true))**|If the device is connected, load the LocalTweets collection from the Twitter service; otherwise, load the collection from the local file cache. |The content is rendered whether the device is online or offline. |
47
-
|**SaveData(LocalTweets, "Tweets")**|Save the LocalTweets collection as a local file cache on the device. |Data is saved locally so that **LoadData** can load it into a collection. |
48
+
|**SaveData( LocalCache, "MyCache" )**| Save the **LocalCache** collection to the user's device under the name "MyCache", suitable for **LoadData** to retrieve later. | Data is saved to the local device. |
49
+
|**LoadData( LocalCache, "MyCache" )**| Loads the **LocalCache** collection from the user's device under the name "MyCache", previously stored with a call to **SaveData**. | Data is loaded from the local device. |
50
+
51
+
### Simple offline example
52
+
53
+
This very simple example captures and stores the names and pictures of everyday items while offline. It stores the information in the device's local storage for later use, allowing the app to be closed or the device to restart without losing data.
54
+
55
+
You must have a device to work through this example as it uses the **LoadData** and **SaveData** functions that do not operate when in a web browser.
56
+
57
+
1. Create a blank canvas app with a tablet layout. For more details read [creating an app from a template](../get-started-test-drive.md) and select **Tablet layout** under **Blank app**.
58
+
59
+
1. Add a [**Text input**](../controls/control-text-input.md) control and a [**Camera**](../controls/control-camera.md) control and arrange them roughly as shown:
60
+
> [!div class="mx-imgBorder"]
61
+
> 
62
+
63
+
1. Add a [**Button**](../controls/control-button.md) control.
64
+
65
+
2. Double click the button control to change the button text to **Add Item** (or modify the **Text** property).
66
+
67
+
3. Set the **OnSeelct** property of the button control to this formula which will add an item to our collection:
> 
73
+
74
+
1. Add another **Button** control.
75
+
76
+
2. Double click the button control to change the button text to **Save Data** (or modify the **Text** property).
77
+
78
+
3. Set the **OnSeelct** property of the button control to this formula in order to save our collection to the local device:
79
+
```powerapps-dot
80
+
SaveData( MyItems, "LocalSavedItems" )
81
+
```
82
+
> [!div class="mx-imgBorder"]
83
+
> 
84
+
85
+
It is tempting to test the button, and it won't hurt anything if you want to try, but you will only see an error as we are authoring in a web browser. You must first save the app and open on a device before we can test this formula which we will do in the steps to follow.
86
+
87
+
1. Add a third **Button** control.
88
+
89
+
2. Double click the button control to change the button text to **Load Data** (or modify the **Text** property).
90
+
91
+
3. Set the **OnSeelct** property of the button control to this formula in order to load our collection from the local device:
92
+
```powerapps-dot
93
+
LoadData( MyItems, "LocalSavedItems" )
94
+
```
95
+
> [!div class="mx-imgBorder"]
96
+
> 
97
+
98
+
1. Add a [**Gallery**](../controls/control-gallery.md) control with a Vertical layout that includes a picture and text areas:
99
+
> [!div class="mx-imgBorder"]
100
+
> 
101
+
102
+
1. When prompted, select the **MyItems** collection as the data source for this gallery. This will set the **Items** property of the **Gallery** control:
103
+
> [!div class="mx-imgBorder"]
104
+
> 
105
+
The image control in the gallery template should default its **Image** property to **ThisItem.Picture** and the label controls should both default their **Text** properties to **ThisItem.Item**. Check these formulas if after adding items in the following steps you don't see anything in the gallery.
106
+
107
+
1. Position the control to the right of the other controls:
108
+
> [!div class="mx-imgBorder"]
109
+
> 
110
+
111
+
1. Save your app. If it is the first time it has been saved, there is no need to publish it; if not, also publish the app.
112
+
113
+
1. Open your app on a device such as a phone or tablet. **SaveData** and **LoadData** cannot be used in Studio or in a web browser. Refresh your app list if you don't see your app immediately, it can take a few seconds for the app to appear on your device. Signing out and back in to your account can help too.
114
+
> [!div class="mx-imgBorder"]
115
+
> 
116
+
Once your app has been downloaded, you can disconnect from the network and run the app offline.
117
+
118
+
1. Enter the name and take a picture of an item.
119
+
120
+
2. Select the **Add Item** button. Repeat adding items a couple of times to load up your collection.
121
+
> [!div class="mx-imgBorder"]
122
+
> 
123
+
124
+
1. Select the **Save Data** button. This will save the data in your collection to your local device.
125
+
126
+
1. Close the app. You collection in memory will be lost including all item names and pictures, but they will still be there in the device's storage.
127
+
128
+
1. Launch the app again. The collection in memory will again show as empty in the gallery.
129
+
> [!div class="mx-imgBorder"]
130
+
> 
131
+
132
+
1. Select the **Load Data** button. The collection will be repopulated from the stored data on your device and your items will be back in the gallery. Note that the collection was empty before this button calls the **LoadData** function; there was no need to call **Collect** or **ClearCollect** before loading the data from storage.
133
+
> [!div class="mx-imgBorder"]
134
+
> 
135
+
136
+
1. Select the **Load Data** button again. The stored data will be appended to the end of the collection and a scroll bar will appear on the gallery. If you would like to replace rather than append, use the **Clear** function first to clear out the collection before calling the **LoadData** function.
137
+
> [!div class="mx-imgBorder"]
138
+
> 
139
+
140
+
### More advanced offline example
141
+
142
+
For a detailed example, see the article on [simple offline capabilities](../offline-apps.md).
0 commit comments