cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Meneghino
Level 10

Re: Patch a Collection

You are welcome.

The way I understand it, it is cleaner to use AddColumns instead of ForAll when you just need to calculate a value.  I reserve ForAll for when there is a real need to use actions.

Meneghino
Level 10

Re: Patch a Collection

You are right, @Mike8, only the second part.

Here is the first part, with a bit of a cheat...

ClearCollect(Collection1,{Letter:"A",Number:1},{Letter:"B",Number:2},{Letter:"C",Number:3});
ClearCollect(Collection2,{SecondNumber:4},{SecondNumber:5},{SecondNumber:6});
ForAll(Collection2, Patch(Collection1, Last(FirstN(Collection1, SecondNumber-3)), {Number: SecondNumber}))

If you don't want to cheat, just add an index to both collections.

Mike8
Level 10

Re: Patch a Collection

Perfect. Thank you again @Meneghino.

Especially your first answer about the second part of my question really helped me.
I was using this:
ClearCollect(Collection3, AddColumns(Collection1, "New_column", Collection2.SecondNumber))
and I had the Collection2.SecondColumn in every record in a nested structure.
Problem solved. Smiley Happy

kullurumanoj
Level: Powered On

Re: Patch a Collection

 

This is the property I have setup to add data to sql server..getting error ; the first argument of patch should be a collection

 

Patch('[dbo].[Sample]',Defaults('[dbo].[Sample]'),
{
Organisation : DataCardValue15.Text,
Line_of_Business Smiley Very HappyataCardValue16.Text,
Industry Smiley Very HappyataCardValue18.Text ,
Director Smiley Very HappyataCardValue19.Text ,
Product Smiley Very HappyataCardValue20.Text ,
Engineering_Manager Smiley Very HappyataCardValue21.Text,
Metrics_Reporter : DataCardValue22.Text })

Meneghino
Level 10

Re: Patch a Collection

Hi @kullurumanoj

I believe the error is related to your table structure.  The SQL table should have a primary key defined.

For example, see here:

https://powerusers.microsoft.com/t5/General-Discussion/Patch-problems-with-on-premises-SQL-gateway/m...

 

kullurumanoj
Level: Powered On

Re: Patch a Collection

Heyy bro.. thanks it did work and the problem is when I try to edit the previous record ,a new record with the edited field is getting created instead of updating old record.

Meneghino
Level 10

Re: Patch a Collection

What happens depends on the second parameter of the Patch.

Use defaults to create a new record, or a simple record with primary key values to edit an existing record.

Like this:

Patch(DataSource, {ID: 123}, {TextColumn: "Foo"})

PS You can get better performance if you avoid the use of Defaults():

https://baizini-it.com/blog/index.php/2018/01/11/powerapps-replace-the-defaults-function-to-improve-...

kullurumanoj
Level: Powered On

Re: Patch a Collection

hey my primary key is UID,but whenever I try to edit other fileds it says The item has already been created on the server, but able to edit UID and also it gets created as new record with edited UID,rest with same properties..I am a beginner need some help with this

 

Here is my code ;

 

Patch('[dbo].[Sample]',{UID:Blank()},
{UID : DataCardValue21.Text,
Organisation : DataCardValue22.Text,
Line_of_Business : DataCardValue23.Text,
Industry : DataCardValue24.Text ,
Director : DataCardValue25.Text ,
Product : DataCardValue26.Text ,
Engineering_Manager : DataCardValue27.Text,
Metrics_Reporter : DataCardValue28.Text });
Navigate(BrowseScreen1, ScreenTransition.None);Refresh('[dbo].[Sample]')

Highlighted
Meneghino
Level 10

Re: Patch a Collection

Hi @kullurumanoj

If you are still having issues please get in touch via private message and I will try to see what is going on.

Thanks.

kullurumanoj
Level: Powered On

Re: Patch a Collection

Was able to figure that out ..Thanks for the help

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Demo Extravaganza Championship Voting Open

Voting Ends: October 30, 2019!

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 168 members 4,859 guests
Please welcome our newest community members: