Canvas Apps Code Sample Error Management

A simple way to implement error handling

A 404 error!
A 404 error!

Introduction to error handling

Error handling is super critical for any application. It makes for a much better user experience when users know that they have run into an issue. It makes it even better if they are told what they issue than ran into. There are quite a few helpful functions available in Power Apps. To learn more about the functions, click here.

Error handling - a simple way

The App control has an OnError property. Set it to:

Set(
    gblIsError,
    true
);
Notify(
    "Error: " & Substitute(
        Last(
            Split(
                FirstError.Message,
                """message"":"
            )
        ).Value,
        "}}",
        ""
    ),
    NotificationType.Error,
    0
);

Now, wherever you have a Patch function, all you have to do is set the variable gblIsError to false. Here is an example:

Set(
    gblIsError,
    false
);
Patch(
    Table,
    Defaults(Table),
    {ColumnA: "1234"}
);

If the Patch function runs into an error, the exact error message will get notified!

Recent articles

  1. How to patch images from Dataverse to D365 F&SC
  2. How to patch images from Power Apps to Dataverse
  3. How to patch images from Power Apps to D365 F&SCM

Leave a Reply