Skip to content

Canvas Power Apps and offline use – Building in practice

Canvas Power Apps has long had native support for offline use. In certain use cases, it’s a really cool feature. In theory, making an app that can be used offline is really simple. In practice, it’s not always so simple.

This spring, I updated a large application to work offline. In this article, I’ll go over the challenges I faced during the project.

If you are not already familiar with using Power Apps offline, you should start by reading my three previous articles on the topic.

Example – Field worker mobile app

The change targets a large-scale Canvas Power Apps implementation, which allows users to, among other things, log hours, perform risk assessments, and update inspection and maintenance activities.

The application uses ~40 Dataverse tables and consists of ~30 screens.

All of this should work without an internet connection.

Offline usage limitations

The very first thing you should do is familiarize yourself with the limitations of offline use.

  • Works only with Dataverse. Forget SharePoint and SQL
  • Virtual table are not supported. Forget about using the Entra ID Users table.
  • Elastic tables are not supported.
  • Notes table usage is not supported.
  • You can sync up to 3 million rows to the device.
  • Power Fx’s Relate and Unrelate functions are not working
  • Many-to-many relationships are not supported.
  • Lookup fields can be nested one relation forward. Filter(Site, Country.CountryCode =”FI”) works, while Filter(Site, Country.RiskCategory.Name=”High”) does not.
  • A lookup field cannot refer to itself. LookUp(Site, ParentSite.Site = locCurrentSite) does not work.
  • Calculated and rollup colummns are only updated when their values ​​are synced back to Dataverse.
  • The order of the rows may differ from what you expected. It is therefore recommended to sort the rows yourself in Power Apps.

Most of the limitations are manageable. In practice, I had to:

  • Replace many-to-many relationships with my own tables
  • Recycle image files via Dataverse to SharePoint (originally saved directly to SharePoint)
  • Change flows that start from Power Apps to start from a change in Dataverse
  • To test whether user-uploaded images can also work offline. Fortunately, the original implementation worked as is.

Once any obstacles caused by restrictions have been addressed, we can move forward.

Offline profile

If the tables used by your application only have a few thousand rows in total, you might consider using an automatically generated profile. It will synchronize all rows from all the tables you need.

In practice, this is rarely possible. Our sample application has over a million rows. Downloading them to the user’s phone doesn’t make sense. And it’s not fast.

An offline profile should be built that synchronizes only the necessary rows to the user’s device. At its simplest, for example, the current month’s active orders.

In our example, the offline profile is largely based on relational chains.

  • All work orders where the user is the owner
  • All products and customers related to these work orders
  • All work instructions related to these products
  • All locations associated with these customers
  • etc

This way, only the necessary information is synchronized to the user’s device.

However, be prepared for problems if the data model is large. The maximum length of relational chains connected to a table is 15.

Practical conversion of an existing application

It’s best to do the change in (really) small chunks. Constantly testing on a mobile device. I first made a copy of the existing application and changed it to support offline use using my new offline profile.

And then test and make corrections one screen at a time.

  1. Add the tables needed for the display to the offline profile. Think about the logic for synchronizing the tables’ rows.
  2. Make sure the user has the necessary access to the needed rows
  3. Publish offline profile
  4. Check on your mobile device that the rows of the required tables are synced to the device
  5. Check on your mobile device that the screen you are testing is working. No errors, and all information appears on the screen as if you were using the same application on a workstation browser (with the same user)

Once you have the screen working, you can move on to the next step.

Sounds easy and fast. However, in my experience, problems do occur. Some are quick to fix by adding the missing table to the offline profile. When changing an existing application, you can also encounter more or less mysterious things.

Typical problems

The initial situation may be that, for example, the gallery is completely empty. Even though it should display all kind of interesting data. In this case, the first thing to do is to check whether the table(s) used by the gallery, including their rows, are synchronized to the device.

Unfortunately, the iPhone screen only shows the first 10 tables. We can’t see the rest. The iPad shows a little more, but not all of them. It would be great if this screen could be scrolled…

If the necessary rows have been synced to the device, you can use the CountRows function to check if they are readable by the application. If they are not, check the access roles. If they are, there is something wrong with the gallery.

The problem is either in the filter condition or in the content displayed in the gallery. Test the filter condition with the CountRows command (CountRows(Filter(condition you used)) by setting it as the value of a text field on the screen, publishing the app, and testing on a mobile device.

If the filter condition returns rows, the reason is in the content displayed in the gallery. One by one, comment out all the code in the gallery that display information from a table other than the one used by the gallery. For example

  • Text = ThisItem.Customer.Name
  • Text = ThisItem.Customer.Country.Name (this is not supported)

Publish and test. It will probably work. Then you re-enable the commented code until you find the source of the problem and fix it. Usually the reason is that the referenced record is not included in the synchronized content. Filing the profile will fix the problem in this case. In some situations, you will have to bend over and retrieve the data with LookUp.

  • Text = LookUp(Country, Country = ThisItem.Country).Name

If the application is used only on mobile, LookUps made within the gallery are not the same kind of poison as normal. The query is always made to the database located on the mobile device, not to Dataverse.

It’s easier to work in small chunks. Don’t make changes to both the app and the offline profile at the same time. When something breaks, you can’t be sure why it broke.

Error messages

When building an application, the most typical error message is the generic “Error while trying to retrieve data from the network”.

It usually means that you are referring to information in the app that is not found in the offline profile.

If the user does not have sufficient permissions to access the table, the platform (usually) gives a proper error message.

Mystical problems

Finally, a few slightly more unusual problems that I have encountered. The most annoying aspect of offline support is the nonsensical error messages. Usually, if something doesn’t work, the user gets a vague “Error while trying to retrieve data from the network” message or no error at all. Once everything is fixed, the application works perfectly. But hunting down errors is sometimes really tedious.

Reinstalling Power Apps

If the app gives a generic “Error while trying to retrieve data from the network” message even though you think everything should be fine, it’s a good idea to uninstall the Power Apps app from your mobile device and reinstall it.

This has fixed the error a few times. When making a lot of changes, either the app or the offline profile can get stuck on the device.

Renaming variables and collections

An old trick from the early days of Power Apps. When converting an existing app, it can happen that collections no longer load values. Even though everything should be fine. In this case, it is worth renaming the collection.

It seems that sometimes the wrong schema gets stuck in the collections, and it can’t load all the necessary information offline. Especially behind the relation.

The same applies to variables.

Mystical image field

The example application has a screen where a row is updated by adding image files (signatures) to two of its columns. The patch command always returned a generic error. However, the data was saved. But the error could not be left to haunt.

What was strange was that adding a new row worked without an error. The error only occurred during the update.

Finally, I discovered that the error does not occur if the update is done by updating the second image field with a blank value. The solution was to finally add a third image field to the table and always add a blank value to it when updating. This way, the other two image fields updated without an error.

Yep. What the heck.

Mystic button

Another crazy situation came up with one of the buttons in the gallery. Pressing the button initializes the collection. Except that in my offline application, the initialization created a collection with no rows. Even though it should.

I made a new screen and a corresponding button there. It worked. I copied the button to the original screen, and the button stopped working. I copied the button to my new screen, and it didn’t work there either.

I had 4 identical buttons on two different screens. Only one of the buttons worked.

The solution, of course, was to move the content of the old screen to the new screen where there was a working button.

Application export + import

The previous two problems were so mysterious that I had to try downloading the entire treatment to my own computer and back. This procedure can sometimes fix completely mysterious problems. Not this time.

Summary

Although the end of the story may sound scary, I don’t think there’s anything to be afraid of with Canvas Power Apps offline support. The issues I encountered were mainly because I was working on a fairly complex application that had been developed for several years. And sometimes there are mysterious problems with them without even an offline story.

If you can start from scratch, there are fewer problems to be had. Even then, I would approach the implementation a little differently than with traditional canvas apps. I would test it frequently on a mobile device. That way, when an error message appears or the screen goes blank (and one of those will happen sooner or later in development), it is much easier to figure out what is causing the error.

However, I can’t recommend this game for complete beginners.

Canvas Power AppsField WorkersofflinePower Apps

Leave a Reply

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

Forward Forever logo
Cookie settings

This website uses cookies so that we can provide you with the best possible user experience. Please select the cookies you want to allow.