Introduction
While working with Power Apps and SharePoint, developers often face unexpected issues when saving data using the Patch() function.
Common problems include:
Duplicate records getting created
Records not updating correctly
Patch silently failing
Wrong record getting modified
Form submission working but Patch not working
In this article, we will explore a real-world scenario where Patch() creates duplicate records instead of updating the existing record — and how to fix it properly using best practices.
Real-World Scenario
You have a SharePoint list named:
ProjectRequests
Columns:
ID (System generated)
Title (Single line of text)
EmployeeID (Single line of text)
ProjectName (Single line of text)
Status (Choice)
RequestDate (Date)
You want to:
The Problem – Duplicate Records Getting Created
You wrote this formula:
Patch(
ProjectRequests,
Defaults(ProjectRequests),
{
Title: TextInput_Title.Text,
EmployeeID: TextInput_EmpID.Text,
ProjectName: TextInput_Project.Text,
Status: Dropdown_Status.Selected.Value,
RequestDate: Today()
}
)
⚠️ Issue:
Every time the user clicks Save, a new record is created, even when updating.
Why?
Because Defaults(ProjectRequests) always creates a new record.
Understanding Patch Behavior
Patch() requires:
Patch(DataSource, BaseRecord, ChangeRecord)
If BaseRecord is:
Defaults(DataSource) → creates new record
Gallery.Selected → updates existing record
LookUp() → updates matched record
Correct Approach – Update If Exists, Otherwise Create
Step 1: Check If Record Exists
We assume uniqueness based on:
EmployeeID + ProjectName
Use:
Set(
varExistingRecord,
LookUp(
ProjectRequests,
EmployeeID = TextInput_EmpID.Text &&
ProjectName = TextInput_Project.Text
)
);
Step 2: Conditional Patch
Now write:
If(
IsBlank(varExistingRecord),
Patch(
ProjectRequests,
Defaults(ProjectRequests),
{
Title: TextInput_Title.Text,
EmployeeID: TextInput_EmpID.Text,
ProjectName: TextInput_Project.Text,
Status: Dropdown_Status.Selected.Value,
RequestDate: Today()
}
),
Patch(
ProjectRequests,
varExistingRecord,
{
Title: TextInput_Title.Text,
Status: Dropdown_Status.Selected.Value,
RequestDate: Today()
}
)
);
Now:
✅ No duplicates
✅ Controlled logic
✅ Clean behavior
Handling Silent Patch Failures (Advanced Issue)
Sometimes Patch does not throw visible errors.
To handle this properly, use IfError().
Step 3: Add Error Handling
IfError(
Patch(
ProjectRequests,
varExistingRecord,
{
Status: Dropdown_Status.Selected.Value
}
),
Notify("Something went wrong while saving.", NotificationType.Error),
Notify("Record saved successfully.", NotificationType.Success)
);
This ensures:
Step 4: Prevent Double Click Duplicate Submission
Another common issue is users clicking Save multiple times quickly.
Solution:
Add a loading variable
Set(varLoading, true);
Patch(
ProjectRequests,
varExistingRecord,
{
Status: Dropdown_Status.Selected.Value
}
);
Set(varLoading, false);
Set button property:
DisplayMode = If(varLoading, DisplayMode.Disabled, DisplayMode.Edit)
This prevents duplicate clicks.
Step 5: Use Form Mode Properly (Alternative Professional Approach)
Instead of manual Patch logic, you can:
EditForm(Form1);
NewForm(Form1);
SubmitForm(Form1);
Use:
OnSuccess → Notify("Saved successfully")
OnFailure → Notify("Error occurred")
Forms automatically manage:
New vs Edit mode
Record binding
Error handling
Performance and Best Practices
✔ Always use LookUp() to identify update records
✔ Never use Defaults() when updating
✔ Avoid using ID manually for new records
✔ Use IfError() for production apps
✔ Disable Save button during submission
✔ Add unique column validation at SharePoint level
Before vs After Implementation
| Scenario | Result |
|---|
| Using Defaults() always | Duplicate records |
| No LookUp logic | Wrong record update |
| No error handling | Silent failure |
| Controlled Patch logic | Stable and reliable |
Output
After implementing this solution:
Conclusion
Handling Patch() properly in Power Apps is critical in enterprise applications.
The most common mistake developers make is always using Defaults() without checking whether a record already exists.
By implementing:
LookUp-based validation
Conditional Patch logic
Error handling
Click prevention logic
You can ensure stable, scalable, and production-ready Power Apps solutions.