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 / ForAll Patch Statement...
Power Apps
Answered

ForAll Patch Statements Skipping Records

(0) ShareShare
ReportReport
Posted on by 38

Hello,

 

In my app I am working with large datasets, specifically where one record can be associated with 10+ records in another table. It is a many-to-many relationship in SQL, so I am using a Junction (or link) table to solve this. For example, if a record of ID=1 is associated with 10 other records of IDs 1-10, there would be ten entries in that table, like:
1 1

1 2

.

.

.

1 10

 

I am doing this by looping over the combobox where the 10 records are, and then using a ForAll and nested patch to insert the 10 rows into my table. Like this:

mstrawn_0-1657053258701.png

 

My issue is that sometimes, like 1 out of 5, the ForAll and patches will just not fully work. They will only insert 7 out of 10 records, or other ones won't work. I am really curious why. I have spent days looking in the Monitor tool, and I can't figure it out. It is like it just randomly skips over some data. Is there a lag/size limit?

Any thoughts are appreciated,

Thanks!

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @mstrawn 

    I would first start with using the ForAll properly in the formula.  You are trying to use it like a For Loop...which it is not.  It is a function that returns a table.  It just so happens that Patch accepts a table of records to patch.

     

    So your formula should only be the following:

    Concurrent(
     Patch(DetectionToolToRule,
     ForAll(ercbDetectTool.SelectedItems,
     {DetectionTool_id: key_id,
     Rule_id: Value(ertxtRule_key_id.Text)
     }
     )
     ),
     Patch(ResponseActionToRule,
     ForAll(ercbResponseAction.SelectedItems,
     {ResponseAction_id: key_id,
     Rule_id: Value(ertxtRule_key_id.Text)
     }
     )
     ),
     Patch(ScopeToRule,
     ForAll(ercbScope.SelectedItems,
     {Scope_id: key_id,
     Rule_id: Value(ertxtRule_key_id.Text)
     }
     )
     )
    )

     

    When you use a Patch in a ForAll like a for loop, Patch has to instantiate itself on each iteration of the for all table record.  This is a huge overhead and leads to horrible performance.  With the above, Patch is instantiated once and provided a table of records to patch.  Since you are not supplying a primary key to the patch, it is smart enough to know to create the record.

     

    I point this out because your scenario seems to indicate a lag in performance that potentially is causing the issue on the database side.  So, put the above in place and at least eliminate the performance factor.

     

    I hope this is helpful for you.

     

  • mstrawn Profile Picture
    38 on at

    @RandyHayes 

    This does make sense, thank you for the explanation.

    When implementing, I am getting this error:

    mstrawn_0-1657068914360.png

     

    It's almost like it is not trying to create new records, which it should be?

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @mstrawn 

    Sorry for delay in this and I believe we solved this in the other thread...it is because those columns are primary keys...they should not be or Patch will try to update them.

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 400 Most Valuable Professional

#2
11manish Profile Picture

11manish 141 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard