Blog

AdobeStock_507446030_Editorial_Use_Only

Power Platform: Making apps that work offline

The Power Platform is an amazing platform to rapidly develop applications that integrate to a huge number of different systems. But did you know that you can use the same tools to develop an application that will work offline, even if it does read and write data from online systems?

Sounds too good to be true, right?

It’s possible, but it’s not magic. It won’t read or write data back while offline, it requires a lot more development, and it still requires the app to be downloaded and launched the first time while you’re online, but there’s still a remarkable amount that can be do if you expect to need to take your app places that the internet just doesn’t reach.

The trick to all of this is using two functions called ‘SaveData’ and ‘LoadData’, to build a local cache.

These concepts work in Teams and Web clients, but they are really designed to work best on Mobile. For information on limits, see the Microsoft documentation:

SaveData, LoadData, and ClearData functions in Power Apps – Power Platform | Microsoft Docs

A typical PowerApp loads data when it launches, and then saves data when it’s complete. This data is sent and received through ‘Connectors’, which act as integration points to other systems. Using this, data can be read or written to SharePoint, Exchange, SQL Server, Web Services, or many, many more places. The architecture looks something like this:

Figure 1: Online-only Power App

But if you have no internet connection, the connectors will fail to read or write the data. The data will be constrained to what is already in the PowerApp, and will fail on load, or on save.

SaveData allows you to write to storage located on the device the Power App has been launched from. LoadData will allow you to retrieve that data whenever you want. If you want to get rid of that data, you can call ClearData.

Using these three methods, you can update your architecture to the following:

Figure 2: Offline-enabled Power App

When you use a Power App to interface with data, instead of using the collections provided by the Connector, have your own in-memory collections. These collections can be saved and loaded as necessary from local storage, which means if you are offline, you can avoid using the connectors entirely.

To complete your app, make sure you have each of the following happening:

  • When the app loads…
    • With connectivity:
      • Submit previous ‘Destination’ local data that was not able to be saved, then clear submitted ‘Destination’ local data to ensure it is not resubmitted.
      • If previous ‘Destination’ data was in the storage but was not flagged as ‘Ready to submit’, query if the user wishes to ‘Resume’ their submission with this data.
      • Load ‘Source’ local data if available. Optionally, let the user interact with the app at this point for best performance.
      • Check the ‘Source’ connector to see if any ‘Source’ local data is out of date and needs to be updated. Update both the in-memory collection and the local storage if there is
    • Without connectivity:
      • Load ‘Source’ local data if available. Present an error to your user if there is none.
      • Allow the user to continue to use your app in ‘Offline’ mode
  • Using a timer, every second…
    • With connectivity:
      • Check if there is anything in the ‘Destination’ local data and submit it if there is anything ready to be submitted. Clear the local data if it is submitted.
      • (Optional) Write the current ‘Destination’ data (even if not submitted) to the local storage, including a flag if it should not be submitted.
      • If ‘Source’ data was not loaded when the app first loaded, load the ‘Source’ data and update the in-memory collection and local storage.
    • Without connectivity:
      • (Optional) Write the current ‘Destination’ data (even if not submitted) to the local storage, including a flag if it should not be submitted, so that a user can ‘Resume’ if the app crashes/is closed without submitting.
  • When data is ‘Submitted’
    • With connectivity:
      • Submit the data. Clear the submitted data from the Local Storage, if a ‘Draft’ version had been stored there.
    • Without connectivity:
      • Write the submitted data to the ‘Destination’ local storage and notify the user that the data will be submitted next time an internet connection is found and the app is launched.

For a technical guide on how to implement some of the concepts detailed in this post, check out this guide from Microsoft:

Develop offline-capable canvas apps (contains video) – Power Apps | Microsoft Docs

If you’re looking to automate business processes through innovative, user-driven applications, we can provide the data management, security and governance support you need to succeed. Get in touch with us to find out more.