Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

How to patch multiple records at once

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!
  • Verified answer
    KeithAtherton Profile Picture
    KeithAtherton 3,460 on at
    How to patch multiple records at once
    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
                    }
                }
            )
        )
    );
     

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

October 2024 Newsletter…

October 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #4 How to Conntact Support…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 142,523

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,707

Leaderboard