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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Cannot nest IfError wi...
Power Apps
Answered

Cannot nest IfError with If when using patch

(0) ShareShare
ReportReport
Posted on by 6

I am currently using IfError to do error handling with patch functions within my application.  I have a submit function like this which works as expected:

 

 

IfError(
 Patch(
 'SP List',
 Defaults('SP List'),
 {
 ...
 }
 ),
 UpdateContext({showError: true}),
 Patch(
 'SP List 2',
 Defaults('SP List 2'),
 {
 ...
 }
 ),
 UpdateContext({showError: true}),
 ...
)

 

 

However if I then nest that IfError function in an if statement then the IfError then complains about invalid arguments.  Like this:

 

If(
 condition,
 IfError( ... ), <--- error here now
 some other action
);

 

 

I need to be able to only run the update if the conditions are true.  However I can't get it to work with if or switch.

Categories:
I have the same question (0)
  • Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    You should be able to nest the IfError() in an If(). I did a quick test and didn't have any errors, so we would need to see the actual formula to figure out why you are getting the invalid arguments error message.

    You could also use Set() with the Patch() statements to create a variable that would indicate if the Patch succeeded or not. 

     

    Set(varPatchList1 , Patch('SP List1', Defaults('SP List1'),{...}));
    Set(varPatchList2 , Patch('SP List2', Defaults('SP List2'),{...}));
    If(!IsBlank(varPatchList1.ID) && !IsBlank(varPatchList2.ID), "Run Update because both patches were successful", "Don't run the update because at least one of patches failed")
  • Cody1 Profile Picture
    6 on at

    Thanks for the suggestion.  The reason of using the IfError was to prevent the 2nd patch from running if the 1st one fails.  I haven't seen a patch in set before, does that handle that?  Here is the submit function.  The error handling is basic for now but I was planning on using the ErrorInfo that is provided by IfError.  

     

    UpdateContext(
     {
     quantityValue: RoundDown(
     Value(QuantityIncreaseInput.Text),
     0
     )
     }
    );
    
    UpdateContext({canContinue: quantityValue <= SelectedProduct.'Total Quantity'});
    
    If(canContinue,
    IfError(
     Patch(
     'PPE History',
     Defaults('PPE History'),
     {
     Title: "Increase",
     InventoryId: SelectedProduct.ID,
     'Old Quantity': SelectedProduct.'Total Quantity',
     'New Quantity': SelectedProduct.'Total Quantity' + quantityValue,
     'Quantity Requested': quantityValue
     }
     ),
     UpdateContext({showError: true}),
     Patch(
     'PPE Inventory',
     LookUp(
     'PPE Inventory',
     ID = SelectedProduct.ID
     ),
     {'Total Quantity': SelectedProduct.'Total Quantity' + quantityValue}
     ),
     UpdateContext({showError: true}),
     Reset(QuantityIncreaseInput);
     Set(
     SelectedProduct,
     LookUp(
     'PPE Inventory',
     ID = SelectedProduct.ID
     )
     );
     Navigate(
     ViewProduct,
     None
     ),
     UpdateContext({showError: true})
    ),
    UpdateContext({showError: true}));
    
    

     

    IfError is underlined in red with message: 'The function ifError has some invalid arguments'

  • WarrenBelz Profile Picture
    156,454 Most Valuable Professional on at

    Hi @Cody1 ,

    @Jeff_Thorpe is correct in that you should be able to run IfError conditionally, but I don't think that is your problem - you may have too many arguments in your If Statement. Is this what you are trying to do?

    With(
     {
     wContinue:
     RoundDown(
     Value(QuantityIncreaseInput.Text),
     0 
     ) <= SelectedProduct.'Total Quantity'
     },
     If(
     wContinue,
     IfError(
     Patch(
     'PPE History',
     Defaults('PPE History'),
     {
     Title: "Increase",
     InventoryId: SelectedProduct.ID,
     'Old Quantity': SelectedProduct.'Total Quantity',
     'New Quantity': SelectedProduct.'Total Quantity' + quantityValue,
     'Quantity Requested': quantityValue
     }
     ),
     UpdateContext({showError: true})
     );
     IfError(
     Patch(
     'PPE Inventory',
     {ID:SelectedProduct.ID},
     {'Total Quantity': SelectedProduct.'Total Quantity' + quantityValue}
     ),
     UpdateContext({showError: true}
     );
     If(
     !showError,
     Reset(QuantityIncreaseInput);
     Set(
     SelectedProduct,
     LookUp(
     'PPE Inventory',
     ID = SelectedProduct.ID
     )
     ); 
     Navigate(
     ViewProduct,
     None
     )
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Cody1 Profile Picture
    6 on at

    Hi @WarrenBelz , I'm still very new to formula so I'm not sure if your example provides the functionality that I was looking for.  The ultimate goal was to be able to use the IfError as a simple error handler like this:

     

    IfError(
    try 1,
    catch,
    try 2,
    catch,
    try 3,
    catch)

     

     

    Where try2 does not run if try1 fails, and try3 does not run if try2 fails, etc.  I know this is possible using nested if statements but I was trying to take advantage of the power of IfError.  Unless I'm missing something, I don't think my If statement has too many arguments, it has If(bool, IfError(...), UpdateContext(..));

     

    Thanks.

     

  • Verified answer
    WarrenBelz Profile Picture
    156,454 Most Valuable Professional on at

    @Cody1 ,

    Yes, I think you would need to nest that - you do not have GOTO VB commands here unfortunately.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard