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 / SharePoint Patch ForEa...
Power Apps
Unanswered

SharePoint Patch ForEach getting Duplicate errors on Multi-Update

(0) ShareShare
ReportReport
Posted on by 81

I have a collection that stores multiple records for update. I use a ForEach / Patch combo tied to the OnSelect property of a Button, and it works... kinda.

 

The list I'm updating has a unique-required field index field (RMT_EID), and some other fields (one left as an example). When I try to update multiple records, I get an error for adding a duplicate record, for all of the records EXCEPT the last. The LAST changed record DOES work. It's not related to the data, as it is the same outcome regardless of which record is last.

 

The intent is to update the 'R1 Tower Lead EID' field for existing records, not to add anything. I added the 'RMT_EID' field to the Patch to fix an issue where the records were not updating at all... and it fixed that, but seemed to break something else. Thoughts?

Code is:

ForAll(

RenameColumns(Filter(collMultiUpdateChanged, IsChanged),"ID","GalleryID"),

Patch(listName, LookUp(listName,ID=GalleryID),

{ 'RMT_EID': Resource_1.Text,

'R1 Tower Lead EID': TowerLead_1.Selected.Value }

)

By the way @ShaneYoung has an excellent video on updating multiple records (https://www.youtube.com/watch?v=0xZ4fMJbLvk) and I highly recommend you check him out!

Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @SPA :

    The formula looks fine, could you tell me what difficulties you are currently experiencing?

    In additon,If you want to batch update some records, you can also use UpdateIf.

     

    UpdateIf(
     listName,
     ID in Filter(collMultiUpdateChanged, IsChanged).ID,
     { 'RMT_EID': Resource_1.Text,'R1 Tower Lead EID': TowerLead_1.Selected.Value }
    )

     

    Note: These functions cannot be delegated (including ForALL), if the number of records in your data source exceeds 500, it may cause some problems

    Best Regards,

    Bof

  • SPA Profile Picture
    81 on at

    @v-bofeng-msft thanks for the help... the problem is as stated in the original post: When I try to update multiple records, I get an error for adding a duplicate record, for all of the records EXCEPT the last. The LAST changed record DOES work. I need to understand why Power Apps thinks I'm trying to ADD records (hence the error for adding records with an existing value in a "unique" SharePoint list column)

     

    View of data with requested changes highlighted (in last Yes/No column) Rows 1,3,5:

     

    Annotation 2020-08-31 094401.jpg

     

    Error message when I run:

    Annotation 2020-08-31 094713.jpg

    Results after I run. Note that the first 2 are not updated, but the last one is updated:

     

    Annotation 2020-08-31 094805.jpg

     

     

    I use a collection to hold the records I need to update, so Delegation is not an issue... I use filters to restrict the user to ~100 updates at a time. 

     

     

  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @SPA :

    I guess the reason is that in some cycles, LookUp(listName,ID=GalleryID) cannot find the corresponding record.

    Maybe you could try:

     

    ForAll(
     RenameColumns(Filter(collMultiUpdateChanged, IsChanged),"ID","GalleryID"),
     If(!IsBlank(LookUp(listName,ID=GalleryID)),
     Patch(listName, 
     LookUp(listName,ID=GalleryID),
     { 'RMT_EID': Resource_1.Text,'R1 Tower Lead EID': TowerLead_1.Selected.Value }
     )
     ) 
    )

     

    Best Regards,

    Bof

  • SPA Profile Picture
    81 on at

    @v-bofeng-msft, I know the records are in there to match, as they are used to populate the gallery control itself... plus the error describes a "duplication" error for values in a unique column, not a "not found"  error.

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 494

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
11manish Profile Picture

11manish 323

Last 30 days Overall leaderboard