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 Apps
Answered

ForAll Patch Issue

(0) ShareShare
ReportReport
Posted on by 24
Hey I have this statement working for one record at a time in the list called Retention.  It is supposed to bulk replace an email value with a different one.  Can someone please help me to get the ForAll syntax correct so these works all in one go....
 
For example right now, the Patch works on the first record only but will not work on all of the records at once.  The field I am trying to evaluate is a Person Type
 
Patch(Retention,
        LookUp(Retention, Assigned_to_HRBP.Email = galCurHRBP.Selected.Value),
            {
                Assigned_to_HRBP:{'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
                                ,Department: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).department
                                ,Claims: "i:0#.f|membership|" & galNewHRBP.Selected.Value
                                ,DisplayName: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).displayName
                                ,Email: galNewHRBP.Selected.Value
                                ,JobTitle: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).jobTitle
                                ,Picture: ""
                                }
            }
        );
Refresh(Retention);
Categories:
I have the same question (0)
  • Suggested answer
    ronaldwalcott Profile Picture
    3,908 Moderator on at
    Try something like this
     
    ClearCollect(tempCollection, Filter('Job Descriptions', 'Job Title' = "Carpenter"));
     
    ForAll(tempCollection, Patch('Job Descriptions', LookUp('Job Descriptions', 'Job Title'= ThisRecord.'Job Title'), { 'Job Title':"r" }));
     
    as you updating the same table that the ForAll is looping through
  • WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at
    I am assuming here you are wanting to update the Retention SharePoint list with the contents of the galCurHRBP gallery. Assuming you have the ID of the relevant record in the Gallery Items, try this structure. I also assume that you have a field called Value in your gallery containing a valid email address.
    Patch(
       Retention,
       ForAll(
          galCurHRBP.AllItems As _Data,
          With(
             {   
                _ID:
                LookUp(
                   Retention, 
                   Assigned_to_HRBP.Email = _Data.Value,
                   ID
                ),
                _User: Office365Users.UserProfileV2(_Data.Value)
                
             },
             {
                ID: _ID,
                Assigned_to_HRBP:
                {
                   Claims: "i:0#.f|membership|" & Lower(_Data.Value),
                   Department: _User.department,
                   DisplayName: _User.displayName,
                   Email: _Data.Value,
                   JobTitle: _User.jobTitle,
                   Picture: ""
                }
             }
          )
       )
    );
    Refresh(Retention);
    There are a couple of important things here to note - firstly you do not need the odata.type reference anymore, but more importantly the structure of having the ForAll statement inside the Patch, which is farm more efficient/faster as it writes the resulting Table in a single Patch, rather than a data source write for each record.
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee

     
  • mrmmickle1 Profile Picture
    24 on at
    Hey @WarrenBelz, I tried your solution and it didn't work.  It executes but the data is not updated accordingly.  I see your description, which makes me believe that I may not have explained the issue properly.
     
    I have an email address in galCurHRBP (This is a distinct list of emails from Retention)  Each email can be repeated on many records.  The idea is that I will use this value to bulk update.  So this is the the value I want to update.  Matt@Email.com which repeats in the Retention list 5 times on different records will be changed to John@Email.com which is selected in the galNewHRBP gallery.  So essentially it just bulk updates them like a simple SQL update statement.  So I am not trying to go through all items in the gallery, but use only the one that I have selected.  (I hope this makes more sense?)
     
    Basically the selection in galCurHRBP is supposed to be cascaded to all of the records in the retention table with the item selected in galNewHRBP...
     
    @ronaldwalcott
     
    I am close to getting your solution to work.  I have verified that the values in my temporary collection are correct (colRetToUpdate).  I get the three records that I would like to update.  However, I am have trouble getting them to update.  I am getting an error that says "Error when trying to retrieve data from the network. Fetching items failed.  Possible invalid string in filter criteria. (The error is on the lookup).
     
    ClearCollect(colRetToUpdate, Filter(Retention, Assigned_to_HRBP.Email = galCurHRBP.Selected.Value));
    ForAll(colRetToUpdate,
            Patch(Retention, LookUp(Retention, ID = ThisRecord.ID),
                {
                    Assigned_to_HRBP:{'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
                                    ,Department: ""
                                    ,Claims: "i:0#.f|membership|" & galNewHRBP.Selected.Value
                                    ,DisplayName: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).displayName
                                    ,Email: galNewHRBP.Selected.Value
                                    ,JobTitle: ""
                                    ,Picture: ""
                                    }
                }
            )
        );
    Refresh(Retention);
     
    Hope this helps.  I used to answer a lot of forum questions in the excel community, but have very little experience with PowerApps.  Fish out of water...
     
     
     
  • Verified answer
    WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at
    OK - I think I have what you need - this one needs a particular structure when you are updating a data source based on a filter on itself - try this
    With(
       {
          _Data: 
          Filter(
             Retention, 
                Assigned_to_HRBP.Email = galCurHRBP.Selected.Value
          ),
          _User: Office365Users.UserProfileV2(galNewHRBP.Selected.Value)
       },
       Patch(
          Retention,
          ForAll(
             _Data As _D,
             {
                ID: _D.ID,
                Assigned_to_HRBP: 
                {
                   Claims: "i:0#.f|membership|" & Lower(_User.mail),
                   Department: _User.department,
                   DisplayName: _User.displayName,
                   Email: _User.mail,
                   JobTitle: _User.jobTitle,
                   Picture: ""
                }
             }
          )
       )
    )
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee

     
  • mrmmickle1 Profile Picture
    24 on at
    Hey @WarrenBelz
     
    I tried your solution and I am getting an error.  It looks like the intellisense does not recognize _Data (i.e. when I type the "." nothing comes up like I would expect... like ID for example...    I understand the syntax not sure why it's doing that?
     
    I also tried to adapt @ronaldwalcott's solution....  I have it working but I don't think I need the If.... not sure how to remove it as when I tried I just get a ton of syntax errors.  Basically I don't think I need the if at all.  Just wasn't sure how to remove it...
     
    ClearCollect(colRetToUpdate, Filter(Retention, Assigned_to_HRBP.Email = galCurHRBP.Selected.Value));
    ForAll(
        colRetToUpdate,
        If(
            LookUp(
                Retention,
                ThisRecord.ID = colRetToUpdate[@ID],
                "OK"
            )="OK",
            Patch(
                Retention,
                LookUp(
                    Retention,
                    ThisRecord.ID = colRetToUpdate[@ID]
                ),
                {
                    Assigned_to_HRBP:
                    {
                                     Claims: "i:0#.f|membership|" & galNewHRBP.Selected.Value
                                    ,Department: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).department
                                    ,DisplayName: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).displayName
                                    ,Email: galNewHRBP.Selected.Value
                                    ,JobTitle: Office365Users.UserProfileV2(galNewHRBP.Selected.Value).jobTitle
                                    ,Picture: ""
                    }
                }
            ),""
        )
    );
    Refresh(Retention);
    I used his suggestion in addition to this article to make the adjustments:
  • WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at
    Please see amended code
  • Suggested answer
    mrmmickle1 Profile Picture
    24 on at
    @WarrenBelz - Thank you so much for your help.  I marked your answer as the solution.  You rock!

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

#2
11manish Profile Picture

11manish 134 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 101 Super User 2026 Season 2

Last 30 days Overall leaderboard