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

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
    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
    68,697 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
    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
    68,697 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

Forum hierarchy changes are complete!

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

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard