Create custom error messages in Power Apps

We’ve all seen those error messages that don’t make any sense. Have you ever wanted to replace an error messages with your own custom error messages?

Field validation in Power Apps
Field validation in Power Apps

It’s actually not too difficult to replace these error messages.

An example of Custom error messages

Imagine that we have a button in out app that will update a record using the Patch function. Obviously the following example will give us an error.

Code editor displaying a Patch function with a highlighted button labeled 'Button' in a user interface.
Create custom error messages in Power Apps 1

In the OnError property of the App, we could specify how we want an error to appear. In the example below we are adding some text in front of the error message.

Screenshot of a development environment showing the tree view of an app interface with a button labeled 'Button1' and a formula bar displaying a custom notification message.
Create custom error messages in Power Apps 2

This will result in the following error message when we click that button.

Custom error messages in Power Apps
Custom error messages in Power Apps

There have been a few situation in Power Apps where the user only gets “An unknown error occurred”, with the above property you could replace those messages with something more useful.

We could also user the error code to decide what we want to do. This could be a notification, but anything is possible. Maybe we can even fix the issue within the app.

Notify("My Custom Message:" & First(Errors(Accounts)).Error, NotificationType.Error)

Power Apps knows the following kind of errors:

ErrorKindDescription
ErrorKind.ConflictAnother change was made to the same record, resulting in a change conflict. Use the Refresh function to reload the record and try the change again.
ErrorKind.ConstraintViolationOne or more constraints have been violated.
ErrorKind.CreatePermissionAn attempt was made to create a record, and the current user doesn’t have permission to create records.
ErrorKind.DeletePermissionAn attempt was made to delete a record, and the current user doesn’t have permission to delete records.
ErrorKind.EditPermissionAn attempt was made to edit a record, and the current user doesn’t have permission to edit records.
ErrorKind.GeneratedValueAn attempt was made to change a column that the data source generates automatically.
ErrorKind.MissingRequiredThe value for a required column is missing from the record.
ErrorKind.NoneThere’s no error.
ErrorKind.NotFoundAn attempt was made to edit or delete a record, but the record couldn’t be found. Another user may have changed the record.
ErrorKind.ReadOnlyValueAn attempt was made to change a column that’s read only.
ErrorKind.SyncAn error was reported by the data source. Check the Message column for more information.
ErrorKind.UnknownThere was an error, but of an unknown kind.
ErrorKind.ValidationThere was a general validation issue detected, that didn’t fit one of the other kinds.

Now it is easy to create a switch statement to handle each of the error types in a slightly different way.


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.