
Announcements
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!
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!