web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch Function Error H...
Power Apps
Unanswered

Patch Function Error Handling to SQL Server

(0) ShareShare
ReportReport
Posted on by 46

Hi All,

 

Have what I hope is a simple question and looking forward to any advice that can be offered.

 

I am using the Patch function in an App that pushes data to a SQL Server.  I have error handling in place but I'm struggling with how to handle a duplicate error in the app.  Right now I have the following in place:

 

// Check for Errors after the + sign is clicked
If(
IsEmpty(Errors('C21-BudVer')),
// Successful Entry
Notify(
"Version Saved Successfully",
NotificationType.Success
),
// Failed Entry
Notify(
"Error Occurred Version Not Saved",
NotificationType.Error
)
)

 

On the SQL end I have controls in place to prevent duplicate entries, so if a user tries to send a duplicate value I think that the "Error Occurred Version Not Saved" message should appear, but that isn't what is happening.

 

Instead when a User enters a duplicate value, the following message appears "Network Error When Using Patch Function:  The requested operation is invalid."

 

How do I handle this error so that the user knows that their entry failed because they have entered a duplicate item?  It seems to me like the error is happening before the Failed Entry trigger is happening.

 

Any advice would be most appreciated!

Categories:
I have the same question (1)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @More2Learn,

     

    I handle custom errors with the IfError() or If(IsError()) formulas, this might also be useful in your case.

    You would wrap these functions around your Patch() statement in order to catch the error and throw a custom notification instead. Below I will show the architecture for both options which might be applicable to your case:

     

    IfError():

    IfError(
     Patch(
     Datasource,
     Defaults(Datasource),
     {ColumnName: Value}
     );
     Notify(
     "Version Saved Successfully",
     NotificationType.Success
     ),
     //Should above fail, run code below
     Notify(
     "Error Occurred Version Not Saved",
     NotificationType.Error
     )
    )

     

    If() & IsError():

    If(
     //Run code and return true if it failed
     IsError(
     Patch(
     Datasource,
     Defaults(Datasource),
     {ColumnName: Value}
     )
     ),
     //Run if failed
     Notify(
     "Error Occurred Version Not Saved",
     NotificationType.Error
     ),
     //Run if successful
     Notify(
     "Version Saved Successfully",
     NotificationType.Success
     )
    );
    

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard