Patch Function Error Handling Power Apps
Power Apps Patch Function Error Handling
When using the Patch function in Power Apps, simply sending data to a datasource doesn’t guarantee success. Errors can occur due to validation issues, connectivity problems, or insufficient permissions. Without proper error handling, users may unknowingly lose data. This article explains how to implement effective error handling for the Patch function, ensuring a more reliable and user-friendly experience.
Patch Function Error Handling
- Introduction: Error Handling App
- SharePoint List Setup
- Patching A New Record
- Showing A Successful Patch
- Error Handling With The ERRORS Function
- Building A More Helpful Error Message
- Validating A Record Before Patching
Patch Function Error Handling Video
SharePoint List Setup
Create a new SharePoint list called Geography scores with the following columns:
- Title ( Single Line Of text)
- Language (Single line of text)
- Points (Number)
Once some data gets submitted from the app it will eventually look like this but you won’t need to create any rows initially.

Points must be a value between 0 and 100. Edit the Score column and set the minimum/maximum values as shown below.
Patching A New Record
Now lets shift over to making the canvas app. Open Power Apps Studio and create a new app from blank and name the 1st screen Submit. Insert a set of labels and text inputs for the Title, Language & Points as shown below. Place a submit button beneath them.
Create Success Screen As well

Pressing the submit button will create a new record in SharePoint. Write this code in the OnSelect property of the button. You’ll see an error in the navigate function because we haven’t made the Success Screen yet. We’ll do this next.
Patch(
Geography,
Defaults(Geography),
{
Title: TextInput1.Text,
Language: TextInput2.Text,
Points: Value(TextInput3.Text)
}
);
Navigate('Success Screen')
Error Handling With The ERRORS Function
We only want the Success Screen to show if the new record was successfully created in SharePoint. With our current code that will not happen. If the patch function fails the teacher would still be taken to the next screen. Instead, we want the teacher to see an error message and remain on the same screen so they can make any necessary changes and try again.

We can do this by making the following changes to the submit button’s OnSelect property. First, we use the Errors function to check if there were any problems during the latest patch. Errors outputs a table so we’ll evaluate it using the IsEmpty function. Then we’ll use the Notify function to display an error message saying “Test score submission failed.”
// Patch function to create or update a record in the Geography data source
Patch(
Geography,
Defaults(Geography), // Use default values for a new record
{
Title: TextInput1.Text, // Set the Title field to the value from TextInput1
Language: TextInput2.Text, // Set the Language field to the value from TextInput2
Points: Value(TextInput3.Text) // Convert the text input to a number and set the Points field
}
);
// Check for errors in the Geography data source
If(
!IsEmpty(Errors(Geography)), // If there are errors
Notify("Record Not Created", NotificationType.Error), // Show an error notification
Navigate('Success Screen') // Otherwise, navigate to the Success Screen
);
A note about how the Errors function works: each time Patch is used on a datasource it error state gets reset. Therefore, Errors only returns errors resulting from the latest operation on the Test Scores SharePoint list. It does not cumulatively track all of the errors flagged while the app is in use. If that’s how Errors works then why does it output table? A table is needed because a single record can have more than one error (example: 2 columns with incorrect values).
Building A More Helpful Error Message
We now have an error message in place but it doesn’t tell the teacher why saving the test score failed. A more descriptive error message would help! Fortunately, the Errors function returns a table with these columns containing information about why the operation failed.
- Column – name of the column that failed.
- Message – why the error failed.
- Error – type of error
- Record – the complete record that failed update in the database. This will always be blank when creating a record.
To improve the error message, update the submit button’s OnSelect property as shown below. Notice how the Errors function is now inside a Concat function. This allows multiple error messages to be shown if there are more than one.
// Patch function to create or update a record in the Geography data source
Patch(
Geography,
Defaults(Geography), // Use default values for a new record
{
Title: TextInput1.Text, // Set the Title field to the value from TextInput1
Language: TextInput2.Text, // Set the Language field to the value from TextInput2
Points: Value(TextInput3.Text) // Convert the text input to a number and set the Points field
}
);
// Check for errors in the Geography data source
If(
!IsEmpty(Errors(Geography)), // If there are errors
Notify(Concat(Errors(Geography), Column & ": " & Message), NotificationType.Error), // Show an error notification with details
Navigate('Success Screen') // Otherwise, navigate to the Success Screen
);
Validating A Record Before Patching
No one likes getting and error message. So its a good practice to prevent the teacher from submitting an invalid record and failing. We can do this by disabling the submit button when the Score value is falls outside of the required range as shown below.
We’ll use the little-known Validate function to make it easy. Validate checks a record against a datasource and returns any error information without trying to create/update the datasource. When there’s no issues, it returns blank.
Put this code inside the submit button’s DisplayMode property.
// Check for errors in the Geography data source
If(
IsBlank(
Validate(
Geography,
Defaults(Geography),
{
Title: TextInput1.Text,
Language: TextInput2.Text,
Points: Value(TextInput3.Text)
}
)
),
DisplayMode.Edit,
DisplayMode.Disabled
);
We can also take this a step further and highlight the problematic value by using another variation of the Validate function.
If(
IsBlank(
Validate(
'Geography',
"Score",
IfError(Value(TextInput3.Text), 0)
)
),
RGBA(166, 166, 166, 1),
Red
)
Here’s a brief summary of the article on Patch Function Error Handling in Power Apps:
When using the Patch function in Power Apps, errors can occur due to validation issues, connectivity problems, or insufficient permissions. Proper error handling is essential to prevent data loss and ensure a reliable user experience. The article covers:
- SharePoint List Setup: Create a list with columns for Title, Language, and Points.
- Patching a New Record: Use the Patch function to create a new record.
- Error Handling with the ERRORS Function: Check for errors using the Errors function and display error messages with Notify.
- Building a More Helpful Error Message: Use Concat to show detailed error messages.
- Validating a Record Before Patching: Use the Validate function to prevent invalid submissions.
By implementing these techniques, you can handle errors effectively and improve the user experience in your Power Apps applications.
✨ Thanks for reading! ✨
I hope you found this blog on the Microsoft Power Platform helpful! From Power Apps, Power Automate (Cloud & Desktop), Canvas Apps, Model-driven Apps, Power BI, Power Pages, SharePoint, Dynamics 365 (D365), Azure, and more, I cover a wide range of topics to help you harness these powerful tools. Don’t miss out on future tips, tutorials, and insights—hit that subscribe button to get the latest posts right to your inbox. 💌💬 I’d love to hear your thoughts! Drop a comment below with your questions, ideas, or feedback—let’s get the conversation started!🔗 Let’s connect and grow together!
Follow me, Ravindra Jadhav, on your favorite platforms for even more content and updates on Microsoft Power Platform and related technologies:
💼 LinkedIn – Let’s network and share ideas!
💻 GitHub – Explore my projects and code.
🐦 Twitter – Stay updated with quick tips and industry news.
📺 YouTube – Watch tutorials and deep dives on Power Platform, Power Apps, Power Automate, and more! Let’s build something amazing together with Power Platform and Azure! 🚀
3 thoughts on “Patch Function Error Handling Power Apps 2025”