Introduction

While working with Power Apps and SharePoint, developers often face unexpected issues when saving data using the Patch() function.

Common problems include:

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:

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:

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:

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

ScenarioResult
Using Defaults() alwaysDuplicate records
No LookUp logicWrong record update
No error handlingSilent failure
Controlled Patch logicStable 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:

You can ensure stable, scalable, and production-ready Power Apps solutions.