Latest Posts

PowerApps Load previously stored - offline data on device


The LoadData function in Power Apps is used to load data that was previously saved locally on the device using the SaveData function. This function is particularly useful for offline scenarios where you want to cache data on the device so that it can be accessed even without an internet connection.

PowerApps – LoadData() function Syntax

LoadData(CollectionName, Name, [IgnoreNonexistentFile])

  • CollectionName: The name of the collection into which the data will be loaded.
  • Name: The name of the local file from which the data will be loaded.
  • IgnoreNonexistentFile (optional): A boolean value that specifies whether to ignore the operation if the file does not exist. The default value is false.

Notes:

  1. Pair with SaveData: Always use LoadData in conjunction with SaveData to ensure data is correctly saved and loaded.
  2. Error Handling: Use the IgnoreNonexistentFile parameter and conditional logic to handle scenarios where the file might not exist.
  3. Data Size: Be mindful of the data size and device storage limitations when saving and loading large datasets.
  4. Offline Data Storage: Use LoadData to load cached data when the app is offline, improving app usability and performance.
  5. Session Persistence: Persist user sessions or state between app launches by saving and loading data locally.
  6. Data Caching: Cache frequently accessed data locally to reduce network calls and improve app performance.

PowerApps - Basic Usage of LoadData function

Suppose you have saved data locally using SaveData and want to load it back into a collection when the app starts.

  1. Saving Data Locally:
    • Add a Button control to save data.
    • Set the OnSelect property of the Button to:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

SaveData(Products, "ProductsData")

  1. Loading Data Locally:
    • Add another Button control to load the data.
    • Set the OnSelect property of the Button to:

LoadData(Products, "ProductsData", true)

When you click the first button, it saves the Products collection data locally. Clicking the second button will load this data back into the Products collection.

PowerApps – Load offline Data on App Start

You might want to automatically load data when the app starts.

  1. Saving Data Locally:
    • Follow the same steps as in Example 1 to save data using a button.
  2. Loading Data Automatically:
    • Go to the OnStart property of the App.
    • Set the OnStart property to:

LoadData(Products, "ProductsData", true)

This will ensure that the data is loaded into the Products collection whenever the app starts.

PowerApps - Handle Nonexistent File using LoadData function

Suppose you want to load data and handle the scenario where the file does not exist gracefully.

  1. Saving Data Locally:
    • Follow the same steps as in Example 1 to save data using a button.
  2. Loading Data with Error Handling:
    • Add another Button control to load the data.
    • Set the OnSelect property of the Button to:

If(IsEmpty(LoadData(Products, "ProductsData", true)),

    Notify("No data to load", NotificationType.Error),

    Notify("Data loaded successfully", NotificationType.Success)

)

This will notify the user if there is no data to load.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint