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

Notifications

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,705 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.EntityReferenceDrop' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Kalathiya 462

#2
WarrenBelz Profile Picture

Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.EntityReferenceDrop' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. WarrenBelz 397 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.EntityReferenceDrop' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. MS.Ragavendar 326 Super User 2025 Season 2

Last 30 days Overall leaderboard