This app ran into a problem in Power Apps

Today, one of my client’s app showed the This app ran into a problem error.

This app encountered an error that limits its ability to play. Please reload the app. If the issue persists, please contact the app's owner for resolution.
This app encountered an error that limits its ability to play. Please reload the app. If the issue persists, please contact the app’s owner for resolution.

How to debug the This app ran into a problem

First we will need to find out how to reproduce the issue that resulted in the This app ran into a problem message. This can be harder than expected. Quite often when these kind of problems happen and suddenly the app is unusable, you might not exactly remember where you clicked last.

In my case there is a gallery with pages enabled that was generating the error. As I was clicking on the previous or next page every now and then the app would fail. It wouldn’t fail all the time, just every now and then.

My Page controls that generate the error
My Page controls that generate the error

The app wouldn’t crash on a specific page or after a specific number of clicks. It would just randomly give up every now and then.

Back to the basic browser debug options that we have. Within the browser F12 or Ctrl-Shift-I gets me to the developer tools in both Google Chrome and Edge browsers. Then within the Console tab I found the following errors messages:

TypeError: Cannot read properties of null
TypeError: Cannot read properties of null

So now we have two places to investigate. The pagination control and more importantly the gallery that presents data to me.

Finding the solution for This app ran into a problem

This is the challenging part. In the Named Formulas I found a line of code that depended on a control on my screen. Now this works most of the time.

I tried various fixes to the code but none of them really helped, until I came across the following DelayItemLoading property on my Gallery.

DelayItemLoading
DelayItemLoading

Setting the DelayItemLoading to true did the trick.

Now what does DelayItemLoading do? According to the documentation this property delays loading of items (rows) until after the screen first loads.

Now why would this affect Galleries being updated while the screen is already loaded? Anyway the problem is resolved by updating this setting.

If you run into the same problem, please do open a chat, as I would like to know what may be causing this issue in more detail.

Further Solution on this problem

As this issue has happened to me a few more times, I managed to figure out some of the causes. As I have only started to come across this since the introduction of named formulas, it means that the issue must have something to do with named formulas.

The first part of solving a problem is always to reproduce the problem in a reliable way.

In my app I had something like this as a named fomrula.

nfMainScreenGalleryItemsView = If(varReload,
... Something that is slow like multiple filters and searches on data tables ...
)

The nfMainScreenGalleryItemsView named formula is used to feed a gallery in my app.

Then to trigger an update.

Set(varReload, false);
Set(varReload, true);

This now means that the named formula would get updated twice. once on the setting false and once on the setting to true of the variable. To avoid the error it is better to follow the following pattern:

nfMainScreenGalleryItemsView = If(varReload||!varReload,
... Something that is slow like multiple filters and searches on data tables ...
)

And within the app’s code we can then force a reload by toggling the variable value.

Set(varReload, !varReload);

Now that we have reproduced the error, it is possible to understand the problem.

When a named formula gets updated very quickly multiple times. The second update may affect the first update. This is something that should be avoided. Hopefully Microsoft will address this issue soon, however as a developer it is also important to understand how to write robust code.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.