web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to patch multiple ...
Power Apps
Answered

How to patch multiple records at once

(2) ShareShare
ReportReport
Posted on by 364
Hi All,
 
I am trying to use the patch function to add files to rows of data with a file column in Dataverse. The issue is, I cannot find a way to get all the files from my collection properly uploaded to their related rows. Below is some code I am using: 
 
ForAll(
        colPurchaseList,  
        Patch(
            'AUNA Purchase Request Line Items',
            Defaults('AUNA Purchase Request Line Items'),
            {
                Item: ThisRecord.Item,
                'Item Description': ThisRecord.Description,
                'PR#': _newPR,
                Quantity: ThisRecord.Quantity,
                Cost: ThisRecord.UnitPrice,
                'Total Cost': ThisRecord.TotalCost,
                'Unit of Measure': ThisRecord.UnitofMeasure,
                Currency: ThisRecord.Currency,
                Taxable: ThisRecord.Taxable,
                Hyperlink: ThisRecord.Hyperlink,
                GUID: ThisRecord.GUID
            }
        )
    );
ForAll(
    colPurchaseList,
    ForAll(
        ThisRecord.Attachment,
        Patch(
            'AUNA Purchase Request Line Items',
            LookUp('AUNA Purchase Request Line Items', GUID = ThisRecord.GUID),
            {
                'PR Document': {
                    FileName: ThisRecord.FileName,
                    Value: ThisRecord.FileContent
                }
            }
        )
    )
);
 
The issue is it only inserts files into the first row created but not all of them. Despite trying to link the GUID value between records, all my files end up in the first row.
 
Does anyone know what I am doing incorrectly here? any feedback is greatly appreciated!
Categories:
I have the same question (0)
  • Verified answer
    KeithAtherton Profile Picture
    3,707 Most Valuable Professional on at
    Hey. I've encountered a similar issue before and, for me, it helped to alias the records within the nested ForAll() function calls so I'm explicit in which records I'm calling.
     
    I don't know if this code will work but I've tried to illustrate where aliasing can be used - you will likely need trial-and-error to get this code to work:
    ForAll(
        colPurchaseList As PurchaseList,
        ForAll(
            PurchaseList.Attachment As Attachment,
            Patch(
                'AUNA Purchase Request Line Items',
                LookUp('AUNA Purchase Request Line Items', GUID = Attachment.GUID),
                {
                    'PR Document': {
                        FileName: Attachment.FileName,
                        Value: Attachment.FileContent
                    }
                }
            )
        )
    );
     
  • Suggested answer
    BriannaReddick Profile Picture
    30 on at
    Oh I've had this happen as well - I agree that finding another way to alias is probably a good solution. 


    Another thing you could try would be something like this to nest the behavior of adding the attachments right after each record is created instead of as a next set of for all looping.
     
    ForAll(
        colPurchaseList,
        With(
            {CurrentItem: ThisRecord},
            Set(PatchedRecord, 
                Patch(
                    'AUNA Purchase Request Line Items',
                    Defaults('AUNA Purchase Request Line Items'),
                    {
                        Item: CurrentItem.Item,
                        'Item Description': CurrentItem.Description,
                        'PR#': _newPR,
                        Quantity: CurrentItem.Quantity,
                        Cost: CurrentItem.UnitPrice,
                        'Total Cost': CurrentItem.TotalCost,
                        'Unit of Measure': CurrentItem.UnitofMeasure,
                        Currency: CurrentItem.Currency,
                        Taxable: CurrentItem.Taxable,
                        Hyperlink: CurrentItem.Hyperlink,
                        GUID: CurrentItem.GUID
                    }
                )
            );
            ForAll(
                CurrentItem.Attachment,
                Patch(
                    'AUNA Purchase Request Line Items',
                    PatchedRecord,
                    {
                        'PR Document': {
                            FileName: ThisRecord.FileName,
                            Value: ThisRecord.FileContent
                        }
                    }
                )
            )
        )
    );


     

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!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 105 Most Valuable Professional

#2
Haque Profile Picture

Haque 77

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 70

Last 30 days Overall leaderboard