cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
KaiserKid
Level: Powered On

ForAll Patch Collection to SQL Server

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: ForAll Patch Collection to SQL Server

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 } ) );

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: ForAll Patch Collection to SQL Server

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, 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Dual Super User
Dual Super User

Re: ForAll Patch Collection to SQL Server

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 } ) );

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

KaiserKid
Level: Powered On

Re: ForAll Patch Collection to SQL Server

Great catch! Thanks!

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,761)