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 / ForAll Patch Collectio...
Power Apps
Answered

ForAll Patch Collection to SQL Server

(0) ShareShare
ReportReport
Posted on by 4

I am trying to patch an entire collection to a SQL server at one time.  The collection contains unique values.  However when it patches the the SQL server the 1st record gets input for each item.


For example if the collection as 4 records (A, B, C, D), what gets patched to the SQL server is A, A, A, A.  The total number of records patched is correct (if there are 50 records in the collection, 50 records will be added to SQL), but it just keeps repeating the data for the 1st record in the collection.

The code I am using follows this structure:

ForAll(CollectionItems,
Patch(SQL.dbo,
          Defaults(SQL.dbo),
           {Var1: CollectionItem.var1,
            Var2: CollectionItem.var2 } ) );

Any idea as to why only the data from the 1st record is being patched?  Any help would be greatly appreciated!

@Shanescows @Pstork1 

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

    Hi @KaiserKid ,

    Do you want to patch entire collection data back to your SQL Table once time?

     

    Based on the Patch formula that you mentioned, I think there is something wrong with it. I have made a test on my side, please consider modify your formula as below:

    ForAll(
     CollectionItems,
     Patch(
     SQL.dbo,
     Defaults(SQL.dbo),
     {
     Var1: CollectionItems[@Var1],
     Var2: CollectionItems[@Var1],
     Var3: CollectionItems[@Var3],
     Var4: CollectionItems[@Var4]
     }
     )
    );

    When you use ForAll function to patch each record from the collection back to your SQL Table, you should reference the column value from the collection directly, rather than using CollectionItem.Var1, CollectionItem.Var2, CollectionItem.Var3, ... formula.

     

    Best regards, 

  • Verified answer
    Pstork1 Profile Picture
    69,456 Most Valuable Professional on at

    You are very close, but I think you should be using just the field name as the value, not the collection.field name.  This works for me.

    ForAll(testcollect,
    Patch('[dbo].[SQL]',
     Defaults('[dbo].[SQL]'),
     {FieldA: fielda,
     FieldB: fieldb } ) );

     

  • KaiserKid Profile Picture
    4 on at

    Great catch! Thanks!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at
    Spoiler (Highlight to read)
    Hello,
    I'm trying to do the same thing, however, I'm getting error: The specified record was not found. Server Respoinse [dbo] failed" "resource not found"

    I'm using the same formula as described in this thread, however:
    1- SQL table is empty, I'm trying to add records to the table
    2- TRACK field is supposed to be the primary key

    Please see formula below:

    ForAll(CollectInvoices1,Patch('[dbo].[DMFPAYMENTREQUESTENTITY]',Defaults('[dbo].[DMFPAYMENTREQUESTENTITY]'),{TRACK:1,AMOUNT:'Amount Cur',CHEQUECANCELLED:123,PAYMENTMETHOD:'Payment Method',RECID:12,ProjId:"ZZZ",CREATEDON:Invoicedate,CURRENCYCODE:Currency,DATAAREA:"ZZZ",DATE:Invoicedate,OPSACCOUNTINGID:Vendor,OPSID:"AMZ",PAYMENTREFERENCE:"USD",PRINTERLOCATION:"MLT",SYSTEMID:"KKK",STATUSLOG:"KKK",TRFRSTATUS:true}))

    Thank you so much!
    Hello,I'm trying to do the same thing, however, I'm getting error: The specified record was not found. Server Respoinse [dbo] failed" "resource not found"I'm using the same formula as described in this thread, however:1- SQL table is empty, I'm trying to add records to the table2- TRACK field is supposed to be the primary keyPlease see formula below:ForAll(CollectInvoices1,Patch('[dbo].[DMFPAYMENTREQUESTENTITY]',Defaults('[dbo].[DMFPAYMENTREQUESTENTITY]'),{TRACK:1,AMOUNT:'Amount Cur',CHEQUECANCELLED:123,PAYMENTMETHOD:'Payment Method',RECID:12,ProjId:"ZZZ",CREATEDON:Invoicedate,CURRENCYCODE:Currency,DATAAREA:"ZZZ",DATE:Invoicedate,OPSACCOUNTINGID:Vendor,OPSID:"AMZ",PAYMENTREFERENCE:"USD",PRINTERLOCATION:"MLT",SYSTEMID:"KKK",STATUSLOG:"KKK",TRFRSTATUS:true}))Thank you so much!

     

  • Pstork1 Profile Picture
    69,456 Most Valuable Professional on at

    Is the primary key an autogenerated identity key?  If it is you shouldn't specify it in the pattch.

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 875

#2
Valantis Profile Picture

Valantis 530

#3
11manish Profile Picture

11manish 432

Last 30 days Overall leaderboard