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 / Patch only updates one...
Power Apps
Answered

Patch only updates one row

(0) ShareShare
ReportReport
Posted on by 159

Hi 
My Patch function only creates one row....

First I create a collection with mulitple records in it. 

IzabEwa_0-1631093671046.png

Then I patch the collection to the data source

IzabEwa_1-1631093726174.png

but the data source only receives the last record created.. 
What am I doing wrong 

 

Categories:
  • CU-18081211-6 Profile Picture
    9,272 Moderator on at

    @IzabEwa ,

    Supposing that the structure is similar between the datasource PowerSalesLines and the collection LineItems, use:

    Patch(PowerSalesLines, LineItems)

     

  • IzabEwa Profile Picture
    159 on at

    that wont work as i need to add an external field that isnt included in the collection (a guid)

  • CU-18081211-6 Profile Picture
    9,272 Moderator on at

    @IzabEwa ,

    Add that the column to the collection using:

    AddColumns(Collection,"NameOftheColumnAsInDataSource", GuidValueAsNeeded)

     

    Anyway I don't know the background, so you can use ForAll() function ( this approach is time consumer as you make a patch request for each line from your collection):

    ForAll(LineItems, 
     Patch(PowerSalesLines,Defaults(PowerSalesLines),
     {Item_Description:Item_Description,..... }
     )
    )

     

  • IzabEwa Profile Picture
    159 on at

    this updates the record with the last item of the collection x amount of all the items, ie. if there are 8 records and the last one is tomato there will be 8 tomato records 

  • CU-18081211-6 Profile Picture
    9,272 Moderator on at

    Not to get me wrong, With Item_Description, I'm not reffering to the control value, it is the LineItems column Item_Description:

    ForAll(LineItems,
    Patch(PowerSalesLines,Defaults(PowerSalesLines),
    {Item_Description:Item_Description,..... }
    )
    )

     

  • IzabEwa Profile Picture
    159 on at

    That didnt help , the same thing still happens

     

  • SafaK Profile Picture
    62 on at

    you need to use ForAll ( loop to go over all items in the collection and patch one by one) to do the update or create based on what you want with specifying the current record that you want to patch like below, 

     

    ForAll(LineItems, Patch(PowerSalesLine,Defaults(PowerSalesLines),
    {
    Item_Description: ThisRecord.ItemDescription,
    ...
    })
    )

     

    so you need to add (ThisRecord) to make sure that the current item in the loop is selected

  • IzabEwa Profile Picture
    159 on at

    I tried that 

    IzabEwa_0-1631105074237.png

    but i get this error 

    IzabEwa_1-1631105105290.png

     

  • SafaK Profile Picture
    62 on at

    The method and code are correct, the problem seems to be from the value itself inside the collection, it seems the value is empty while it's a mandatory field or the value is not valid.

  • SafaK Profile Picture
    62 on at

    The method and code are correct, the problem seems to be from the value itself inside the collection, it seems the value is empty while it's a mandatory field or the value is not valid

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard