Skip to content

Canvas Power Apps and Offline Use – Introduction

Until a while ago, the only way to enable offline use of Canvas Power Apps was by messing around with the LoadData and SaveData functions. I haven’t dared to build any real implementation on them.

Fortunately, today’s tool palette has something that works for this need. Canvas Power Apps used on mobile can be made natively offline-compatible. In this case, when the app is launched for the first time, all the necessary information data is downloaded to the device. During use, the read and write operations are always done locally. All changes are then synchronized in the background to the Dataverse regularly.

And specifically to the Dataverse. Offline functionality does not work with any other data source.

The beauty of the feature is that the app creator or user doesn’t have to do anything for this. The application fetches regularly updated data from Dataverse. It also takes the changes made by the user there. Fully automatic in the background.

Let’s take a closer look at how to turn on the offline feature and how it works.

Example – Logging tasks

Let’s make an example application with which the property manager can record observations/tasks related to the housing company. Recordings are made, for example, in the basements of apartments, where there is not always a network.

The data model of the solution is simple. We have

  • Tasks
  • Task categories. Each task is related to one class.
  • Accounts. Each task is related to one account.

The mobile application must be able to add and update tasks. If necessary, you must also be able to create new task categories.

Allowing tables to be used offline

The first is to allow the use of tables without a network. In practice, “Can be taken offline” is selected from the properties of each table.

Canvas Power Apps

After this, Canvas Power Apps is created, the settings of which are visited

  • turning on the Can be used offline
  • Auto-generated is selected as the offline profile

The offline profile is used to manage information that is synchronized to the device. Let’s start with the profile created for us by the platform (auto-generated).

After changing the settings, a new screen designed for mobile use will appear in the application.

Let’s make three screens for the application. You can see all entries on the start screen. Entries can be edited and created.

The screen for creating/editing an entry is straightforward. The entries are linked to the account and category.

If necessary, you can create a new category from the form.

In this respect, making an application is no different from making a traditional application.

But using the app is a little bit different.

Using the offline application

Note: For the user to be able to use offline Power Apps at all, he must have read access to the Mobile offline profile table.

The first time the application is used, it downloads all the information needed to use it to the device. Our example application downloads all tasks, task categories and accounts.

During the first start, the user is reminded that the application works even without an internet connection.

Next, let’s do some typical actions to see how the offline app works.

Launching the application (no network)

The offline application can be started without an internet connection. As long as it has sometimes been started with a network connection (the necessary information has been downloaded to the device).

The application reports a lack of network connection. The symbol in the upper right corner also says the same.

Adding a new row (no network)

Adding a new task when the phone is offline. Let’s raise the stakes a bit. First, let’s add a new category (Nurmikko) and add a new task related to it.

The new task appears in the list on the main screen. The symbol in the upper right corner indicates that the device has changes that have not yet been uploaded to Dataverse.

When you press the symbol in the upper right corner, a dialog opens where you can see the synchronization status. Two lines are waiting to be exported to Dataverse when the connection is restored.

When the phone eventually connects to the network, the changed data is automatically uploaded to Dataverse. And yes. The LookUp column (Category) is also correct.

Another user creates new rows

The user has the application open and the device has a working network connection. What happens when someone else creates a new task?

Nothing. The new row does not appear in the mobile application. Not even if the user updates the data source with the Refresh(tasks) function. The new line is not in the device’s local database. Even after restarting the application, the row still does not appear.

Synchronization takes place in the background every 10 minutes (default value). Only after this, the new task is in the device’s local database and available. But it still doesn’t appear automatically in the visible gallery.

The Refresh(tasks) command must still be executed in the application, in which case the new task will appear in the gallery. The gallery also updates naturally when the user adds a new or edits an existing task.

If waiting 10 minutes is overwhelming, the user can force the synchronization to start with the “Check for updates” button found behind the icon in the upper right corner.

However, this can only be done after five minutes have passed since the last synchronization.

The same logic applies to rows deleted and edited by other users.

Users update the same row

Next, let’s try a situation where the user updates the item title directly in Dataverse.

After this, another user updates the title of the same item with the mobile application.

Which of the changes will remain in effect? The one has managed to save to Dataverse first.

The user updates the deleted row

A user deletes an item from the Dataverse. After this, another user edits the same item with their mobile application, which still has the deleted item in its local database.

What happens in synchronization?

The first action performed on Dataverse (item deletion) wins. That is, the item also disappears from the mobile application. At the same time, the changes made by the user will disappear.

Summary

We finally have a working basis for creating mobile Power Apps that support offline use. However, remember the following:

  • Not all Power Fx commands are supported
  • Only Dataverse works offline. You can add other data sources to the application, but they won’t work without a network
  • You cannot launch a cloud Flow from Power Apps when it is offline
  • The device’s local data storage can easily grow large. It is important to optimize what is uploaded there in the first place. More on this in the next part.
Canvas Power AppsDataverseofflinePower Apps

Leave a Reply

Your email address will not be published. Required fields are marked *