cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
r2d2beep
Frequent Visitor

Patch within ForAll to update multiple matching records not working

Hello PowerUsers,

 

I have a form that allows users to edit a number of fields related to an employee. I have a ClearCollect function which creates a collection of all the rows that match the employee name being updated:

 

 

 

 

 

 

ClearCollect(SelectedColleague, Filter(SPList, Colleague_Name = ColleagueNameLabel.Text));

 

 

 

 

 

 

I then have a Patch inside of a ForAll function which uses this collection as a data source, then updates all records in the collection with the updated fields.

 

 

 

 

 

 

ForAll(SelectedColleague As OurData, Patch(SPList, OurData, {Colleague_Name: ColleagueNameLabel_1.Text}, {Manager: {Value: ManagerNameLabel_1.Text}}, {Colleague_Group: ColleagueGroupLabel_1.Text}, {Colleague_Type: ColleagueTypeLabel_1.Text})))

 

 

 

 

 

 

The reason I have this is because a user may change the group or manager that an employee is assigned to for one record, and I would like for these changes to be applied to all records that contain that specific employee. For example, if John Doe is assigned Manager Jane Doe in Record A, and John Doe is also in Records B and C, I want the Patch function to update the Manager field in Records B and C to Jane Doe.  I used the same code that Shane Young

used in his video tutorial on PowerApps UpdateIf (skip to 8:25 minutes in), and it works on his app but not mine. There are no error messages, but it doesn't update the specified fields in all the records with a matching employee name.  Any idea where I might be going wrong? Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @r2d2beep ,

Try this format

ForAll(
   SelectedColleague As OurData, 
   Patch(
      SPList, 
      {ID:OurData.ID}, 
      {
         Colleague_Name: ColleagueNameLabel_1.Text, 
         Manager: {Value: ManagerNameLabel_1.Text}, 
         Colleague_Group: ColleagueGroupLabel_1.Text, 
         Colleague_Type: ColleagueTypeLabel_1.Text
      }
   )
)

 

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.

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @r2d2beep ,

Try this format

ForAll(
   SelectedColleague As OurData, 
   Patch(
      SPList, 
      {ID:OurData.ID}, 
      {
         Colleague_Name: ColleagueNameLabel_1.Text, 
         Manager: {Value: ManagerNameLabel_1.Text}, 
         Colleague_Group: ColleagueGroupLabel_1.Text, 
         Colleague_Type: ColleagueTypeLabel_1.Text
      }
   )
)

 

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.

View solution in original post

Hi @WarrenBelz, thanks for your reply. The part with the {ID: OurData.ID} did the trick when the collection is populated correctly. This isn't always the case though -  I am populating the collection by filtering to only the rows where the colleague is listed. In my test example, the collection is only 2 rows so I don't think it's a memory issue.

 

 

 

ClearCollect(SelectedColleague, Filter(SPList, Colleague_Name = ColleagueNameLabel.Text));

 

 

 

Do you know why the collection isn't collecting? I have also tried Collect instead of ClearCollect, and closing and re-opening the app, but the problem persists. There isn't a pattern to when the collection collects and when it doesn't.

 

**Edit - Putting the ClearCollect function into a separate button from the Patch functions solved the problem. It looks like Powerapps runs into problems if there are two many functions under one button.**

 

Hi @r2d2beep ,

There is nothing wrong with the syntax providing the Colleague_Name exactly equals the ColleagueNameLabel text and it should always collect if so. As a test, put this on a Label

Colleague_Name = ColleagueNameLabel.Text

and make sure it shows true.

Thanks @WarrenBelz , yes the syntax you provided works perfectly. As I mentioned in my reply, it always collects now that the ClearCollect function into a separate button. If the collection is populated, then the Patch function always works. Thanks again.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,254)