Skip to content

Commit f5bf34c

Browse files
authored
Merge pull request #2444 from MicrosoftDocs/gregli-fixes3
Improvements to LoadData/SaveData, logical/display names, and Notify example images
2 parents b33f5d3 + 7fbd64d commit f5bf34c

26 files changed

+194
-39
lines changed

powerapps-docs/maker/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@
569569
href: ./canvas-apps/functions/function-hashtags.md
570570
- name: Hour
571571
href: ./canvas-apps/functions/function-datetime-parts.md
572+
- name: Identifiers
573+
href: ./canvas-apps/functions/operators.md
572574
- name: If
573575
href: ./canvas-apps/functions/function-if.md
574576
- name: IfError

powerapps-docs/maker/canvas-apps/formula-reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Formulas combine many elements. Listed below are:
2424

2525
Other elements include:
2626

27-
* [All operators](functions/operators.md)
27+
* [Operators and identifiers](functions/operators.md)
2828
* [Controls and their properties](reference-properties.md)
2929
* [Data types](functions/data-types.md)
3030

@@ -203,7 +203,7 @@ Other elements include:
203203

204204
**[Ln](functions/function-numericals.md)** – Returns the natural log.
205205

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

208208
**[Location](functions/signals.md)** – Returns your ___location as a map coordinate by using the Global Positioning System (GPS) and other information.
209209

@@ -291,7 +291,7 @@ Other elements include:
291291
**[RoundUp](functions/function-round.md)** – Rounds up to the smallest next number.
292292

293293
## 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.
295295

296296
**[Search](functions/function-filter-lookup.md)** – Finds records in a table that contain a string in one of their columns.
297297

powerapps-docs/maker/canvas-apps/functions/function-savedata-loaddata.md

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ search.app:
1515
- PowerApps
1616
---
1717
# 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.
1919

2020
## Description
2121
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
2828

2929
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.
3030

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).
3232

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

3537
## Syntax
3638
**SaveData**( *Collection*, *Name* )<br>**LoadData**( *Collection*, *Name* [, *IgnoreNonexistentFile* ])
3739

3840
* *Collection* - Required. Collection to be stored or loaded.
3941
* *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.
4143

4244
## Examples
4345

4446
| Formula | Description | Result |
4547
| --- | --- | --- |
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+
> ![A text input and camera control added to a blank screen](media/function-savedata-loaddata/simple-text-camera.png)
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:
68+
```powerapps-dot
69+
Collect( MyItems, { Item: TextInput1.Text, Picture: Camera1.Photo } )
70+
```
71+
> [!div class="mx-imgBorder"]
72+
> ![A button control added with the text "Add Item" and the OnSelect property set](media/function-savedata-loaddata/simple-additem.png)
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+
> ![A button control added with the text "Save Data" and the OnSelect property set](media/function-savedata-loaddata/simple-savedata.png)
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+
> ![A button control added with the text "Load Data" and the OnSelect property set](media/function-savedata-loaddata/simple-loaddata.png)
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+
> ![Gallery variety selection, "Vertical" selected with image and text areas](media/function-savedata-loaddata/simple-gallery-add.png)
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+
> ![Gallery selection of data source](media/function-savedata-loaddata/simple-gallery-collection.png)
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+
> ![Gallery re-positioned to the right of the screen](media/function-savedata-loaddata/simple-gallery-placed.png)
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+
> ![App running with no items added](media/function-savedata-loaddata/simple-mobile.png)
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+
> ![App running with three items added](media/function-savedata-loaddata/simple-mobile-with3.png)
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+
> ![App again running with no items added](media/function-savedata-loaddata/simple-mobile.png)
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+
> ![App running with three items restored after calling the LoadData function](media/function-savedata-loaddata/simple-mobile-load1.png)
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+
> ![App running with six items restored after calling the LoadData function twice](media/function-savedata-loaddata/simple-mobile-load2.png)
139+
140+
### More advanced offline example
141+
142+
For a detailed example, see the article on [simple offline capabilities](../offline-apps.md).
143+
144+
145+
146+
147+
148+
48149

powerapps-docs/maker/canvas-apps/functions/function-showerror.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ Note: This function was previously named **ShowError** when it could only displa
5454

5555
1. Add a **Button** control to your screen.
5656

57-
2. Set the **OnSelect** property of the **Button** to:
57+
2. Set the **OnSelect** property of the **Button** to the formula:
5858

59-
**Notify( "Hello, World" )**
59+
```powerapps-dot
60+
Notify( "Hello, World" )
61+
```
6062
6163
3. Click or press the button.
6264
@@ -66,7 +68,9 @@ Note: This function was previously named **ShowError** when it could only displa
6668
6769
4. Change the type of message to indicate an error. Add a second argument to our formula:
6870
69-
**Notify( "Hello, World", NotificationType.Error )**
71+
```powerapps-dot
72+
Notify( "Hello, World", NotificationType.Error )
73+
```
7074
7175
5. Click or press the button.
7276
@@ -76,7 +80,9 @@ Note: This function was previously named **ShowError** when it could only displa
7680
7781
4. Change the type of message to indicate a warning. Change the second argument in our formula:
7882
79-
**Notify( "Hello, World", NotificationType.Warning, 4000 )**
83+
```powerapps-dot
84+
Notify( "Hello, World", NotificationType.Warning, 4000 )
85+
```
8086
8187
5. Click or press the button.
8288
@@ -86,7 +92,9 @@ Note: This function was previously named **ShowError** when it could only displa
8692
8793
4. Change the type of message to indicate success. Change the second argument in our formula:
8894
89-
**Notify( "Hello, World", NotificationType.Success, 0 )**
95+
```powerapps-dot
96+
Notify( "Hello, World", NotificationType.Success, 0 )
97+
```
9098
9199
5. Click or press the button.
92100

0 commit comments

Comments
 (0)