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 / Check that a ForAll Pa...
Power Apps
Answered

Check that a ForAll Patch was successful

(0) ShareShare
ReportReport
Posted on by 99

Hi, I have an app that patches data from a collection into the CDS.  I accomplished that by using a button control.  Since I can have multiple records in a collection, I use the ForAll expression:

 

ForAll(CollectionA, Patch(Table1, Defaults(Table1), { Field1: Field1, .... Field12: Field12} ))

 

I want to make sure that the patch works, that the data is copied to the CDS table.  Maybe somehow there is a network issue or mobile phone issue that intterrupts the transfer, I want the user to know that, so they can try again.  I have read that this could be accomplished by using the Errors function along with the IsEmpty or IsBlank Functions.  But all the examples i read about is for when using a Patch only.  How can I accomplish this if I am using an ForAll patch?  Thanks.

 

Categories:
I have the same question (0)
  • FernandoTC Profile Picture
    222 on at

    Hi @mahakala_

     

    If something goes wrong during the forall loop, the user will get an error notification at the top of the app. The problem is that this notification will be messy as the common user will not understand it. You can check if a function is having a runtime error by using the function IsError() or perform an action if the function fails during the runtime by using IfError().

     

    Try this:

    IfError(
     ForAll(
     CollectionA,
     Patch(
     Table1,
     Defaults(Table1), 
     { 
     Field1: Field1,
     .... 
     Field12: Field12
     } 
     )
     ),
    Notify(
     "Something went wrong",
     NotificationType.Error
     ),
    Notify(
     "Success",
     NotificationType.Success
     )
    ) 

    This will show a personalized success message or error mesage to warn the user if the App worked successfully or not.

     

    Hope this helps you!


     

  • mahakala_ Profile Picture
    99 on at

    HI @FernandoTC ,

     

    Thanks for your help.  It works, but not what I fully intend it to do.  It does not seem to work in failed network situations.  It does not give the error message, in the user interface, but it will give you a warning in the control.   I figured a network failed would be one of the top reasons why a patch would fail.  

     

    Also is there a way where If the ForAll patch went through successfully, I want to clear some collections and reset a variable?  I tried to put an '&&' along the success notify statement, but that didn't work.  So my workaround currently is just to put the clear statements instead of the success notify statement if it patches successfully.  The downside is that I do not get the successfull notification, but I guess I can always navigate it to a different page and display a successfull msg there.   Is this the right approach you think, or do you have other suggestions I can try?  Thanks.

  • FernandoTC Profile Picture
    222 on at

    HI @mahakala_ 

    Regarding the network failure, you can try using Connection.Connected before the forall statement. This way, it will check your connection before going through the Patching. 
    If you want to execute another statement after the forall, you can use two options:

    • Function Concurrent() allows you to execute several formulas at the same time.
    • If you put ; between two functions, once the first is executed completely, the following function will proceed to be executed.

    I think the final code you need is the following:

    If(
    Connection.Connected,
    IfError(
    Concurrent(
    ForAll(
    _CollectionA,
    Patch(
    Table1,
    Defaults(Table1),
    {Field1: Field1}
    )
    ),
    Notify(
    "Success",
    NotificationType.Success
    ),
    Clear(_CollectionB),
    Reset(_ControlName)
    ),
    Notify(
    "Something went wrong",
    NotificationType.Error
    )
    ),
    Notify(
    "Unable to connect, please check your network",
    NotificationType.Error
    )
    )

    With this syntax, we first check if the Internet connection is ok, if not, we display an error message asking the user to check the connection.

    If the connection is ok, we proceed to execute the concurrent function with the forall() statement, the success notify, and the clear or reset statements. If this goes wrong in any way, the IfError() function will display the error message warning the user that something went wrong.

     

    I tried this solution and the Connection.Connect statement does not work properly if using the web browser as i losses the connection and cannot continue evaluating anything within the app. However, if you are using PowerApps studio, or the mobile/tablet PowerApps app, it will work as intended.

     

    Hope this is what you were looking for.

  • mahakala_ Profile Picture
    99 on at

    Hi @FernandoTC ,

     

    Just wanted to let you know I see your reply since Monday but I have not gotten a chance to try it out yet as I was pulled into something else at work.  Once I do try it out I will let you know how it worked out. Thank you for taking your time to help.

  • Verified answer
    mahakala_ Profile Picture
    99 on at

    Hi @FernandoTC ,

     

    I finally had a chance to try out your code.  I was pulled away for a different project the last couple of weeks and finally gotten a chane to get back to powerapps.  First i have to say, that was tough conceptially, but i was finally able to get myself to wrap my brain around it.  The code does work, but as you said it does not work in the browser but it did work in my mobile powerapps app.  There is another problem that I saw from this, and i'm hoping you can help me.  Using the Concurrent function, after the ForAll Patch and the successful Notify message, I also added the Clear and Set statements, but there is one particular Clear that is giving me errors and I do not understand why because I am already adding two seperate clear on two other collections.  And I am trying to clear the main collection that actually is the data that patches to the CDS.  But when I add this one, it gives me "The function 'Concurrent' has some invalid arguments".  Again all three clears are to clear a collection.  

     

    The second question is, what would normally cause a patch to fail that would invoke the default action of the IfError function.  I'd like to try it to test that scenario.  Thanks again for your help. I am going to check this as a solution.  

     

     

  • mahakala_ Profile Picture
    99 on at

    Hi @FernandoTC ,

     

    Just wanted to let you know I was able to add the third Clear statement to clear the main collection without any errors.  So I was messing around with the semi colins.  Initially, I had only one semi colin right after the patch and before the success Notify.  For some odd reason, Clear(_CollectionMain) would give me an error message, but it does not give me errors if I leave that statement out, even though I have two other clear statements in there.  Then I realize it works if I add a second semi colin right after the success Notify statement and before the Clear statements.  It works but I am confused why it works.  See Below code:

     

    IfError(
    Concurrent(
    ForAll(
    _CollectionA,
    Patch(
    Table1,
    Defaults(Table1),
    {Field1: Field1}
    )
    );
    Notify(
    "Success",
    NotificationType.Success
    );
    Clear(_CollectionMain),
    Clear(_CollectionB),
    Clear(_CollectionC),
    Reset(_ControlName)
    ),

     

    And just following up on the second question is, what would normally cause a patch to fail that would invoke the default action of the IfError function.  I'd like to try it to test that scenario.  Thanks again for your help. I am going to check this as a solution.  

     

    I will have to revisit how to work around the connection.connected when working in a browser.  

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks for the IfError gem here @FernandoTC . I've been using PowerApps for a long time and didn't know about this function. I was always of the mindset that "Patch doesn't give you any error handling". Thanks for opening my eyes!

  • AlexanMarkarian Profile Picture
    8 on at

    Hi Fernando, 

    i have a slightly different case:

    i have a form submitting. On success a check on blank values if performed and no submission is done if blanks are found. i would need to send a notification though. please can you suggest some correction on code?

    ForAll(DCollection,If(!IsBlank(xvaluex),Patch(DatabaseDetails,Defaults(DatabaseDetails),
    {
    CaseNo: Case_No,

    ....,

    ....,
    ParentID:Form1.LastSubmit.ID
    }

    )))

     

     

     

    Thank you,

    Alex

  • AlexanMarkarian Profile Picture
    8 on at

    Hi Fernando, 

    i have a slightly different case:

    i have a form submitting. On success a check on blank values if performed and no submission is done if blanks are found. i would need to send a notification though. please can you suggest some correction on code to send notification?

    ForAll(DCollection,If(!IsBlank(xvaluex),Patch(DatabaseDetails,Defaults(DatabaseDetails),
    {
    CaseNo: Case_No,

    ....,

    ....,
    ParentID:Form1.LastSubmit.ID
    }

    )))

     

     

     

    Thank you,

    Alex

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard