CRM Crate

Storing & accessing the App data in Mobile Device’s storage of Canvas App

We will learn and understand storing & accessing the App data in Mobile Device’s storage of Canvas App. Before we start, make sure to subscribe to CRM Crate so that you can stay up to date in the field of Power Apps.

Storing & accessing the data in Mobile Device's storage of Canvas App

What is the need for storing data in Mobile Device’s storage of Canvas App?

Consider a scenario where we need to save the App’s data and perform set of operations when the mobile device is offline. Such data related requirement which requires dealing with offline devices can be achieved with the below given solution.

Storing & accessing the data in Mobile Device's storage of Canvas App

Using SaveData, LoadData, and ClearData functions for storing data

We will use SaveData, LoadData, and ClearData Power FX functions for storing a collection in Canvas App’s local device.

SaveData (Collection, Name)

The SaveData function stores a collection for later use under a name.
Collection – Required. Collection to be stored or loaded.
Name – Required. Name of the storage.

LoadData (Collection, Name)

The LoadData function reloads a collection by name that was previously saved with SaveData. You can’t use this function to load a collection from another source.
Collection – Required. Collection to be stored or loaded.
Name – Required. Name of the storage. The name must be same to save and load same set of data. The name space isn’t shared with other apps or users.

ClearData() or ClearData(Name)

The ClearData function clears the storage under a specific name or clears all storage associated with the app if no name is provided.
Name – Optional. Name of the storage previously saved with SaveData. If Name is not provided, all storage associated with the app is cleared.

Understanding our use case & scenario

  • We will leverage the SaveData(), LoadData() & ClearData() functions for storing the App data in device’s storage.
Storing & accessing the data in Mobile Device's storage of Canvas App
  • In our scenario, we will collect the data from an user via a Text Input and add the same in a new collection named “CRMCrateItems” on button click as given below.
Collect(
    CRMCrateItems,
    {Item: TextInput.Text}
);
  • A new Gallery control has been added to store the collection. We will save the collection on click of the button “Save Data”. The below given Power FX formula is used for storing the collection in device’s local storage with name “LocalCache“.
SaveData( CRMCrateItems, "LocalCache" )
  • We will load the previously saved cache data on click of the button “Load Data”. The below given Power FX formula is used for loading the cache data from device’s local storage.
LoadData( CRMCrateItems, "LocalCache" )
  • Further, we will clear the data from device’s storage on click of the button “Clear Data”. The below given Power FX formula is used for clearing the cache data from device’s local storage.
ClearData()

The below animation shows the complete implementation of saving & accessing the data in App’s (Mobile Device) local host of Canvas App.

Thus, we learned to store and access the App data in Mobile Device’s storage of Canvas App.


4 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.