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

Patch & ForAll Question

Hello everyone,

 

I have two questions, one about Patch() and the other about ForAll().

 

I am trying to do the following:

I currently have a PowerApp with Offline capability.

This means, on button press i collect all the necessary data in several collections and save them locally with saveData().

 

The problem is, that the Data is a lot and the download takes generally 10+ hours on the mobile phone.

 

As a work around i wanted to implement the ability to only update data that has been modified.

 

As such my question is the following:

1. If I understand it correctly Patch() only works for one Record at a time, not a whole table?

 

2. Is there a way to use the current record of forall()?

e.g.:

ForAll(Collection1, UpdateIf(Collection2, RecID = Coll1.RecID, Coll1.currentRecord))

4 REPLIES 4
Meneghino
Level 10

Re: Patch & ForAll Question

1. You can patch a set of records, just make sure the number of records in the second and third parameters of the Patch() function is the same

2. I normally find that ForAll has bad performance and you can almost always find a substitute

Have a look here:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Patch-multiple-records-with-one-server-call-inst...

Community Support Team
Community Support Team

Re: Patch & ForAll Question

Hi @T_Findeisen,

 

1) Patch can be used to modify or create a set of records in a data source. The syntax is PatchDataSourceBaseRecordsTableChageRecordTable1, [, ChangeRecordTable2, … ] )

 

2) What do you mean by ".currentRecord"? Is this current record mean the current record inside a Form control? 

The synax for ForAll is:

ForAllTableFormula )

 

But the part UpdateIf(Collection2, RecID = Coll1.RecID, Coll1.currentRecord) returns not a formula, but a table. So ForAll function won't work.

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
T_Findeisen
Level: Powered On

Re: Patch & ForAll Question

Hello both,

ty for answering.

 

1. So I cannot use patch a saved collection with new entries into a database?

This means not only update changed records but also include newly added records.

 

 

2. Since RecId is unique per table it should return only 1 record, but the goal isn't to get one record anyways.

As for .currentRecord:

ForAll goes through a table line by line (or record by record).

So If the example is

A   1

B   2

.currentRecord would be (A, 1) in the first loop and (B, 2) in the second loop.

 

I am asking because currently when I want to update my old record with the new record I am doing the following:

 

ForAll(NewCollection; UpdateIf(OldCollection; OC.RecId = NC.RecId; First(Filter(NewCollection; RecId = OC.RecId))))

And sth like

ForAll(NewCollection; UpdateIf(OldCollection; OC.RecId = currentRecord.RecID; currentRecord)

seems a lot easier.

 

Best regards

Meneghino
Level 10

Re: Patch & ForAll Question

@T_Findeisen

It is difficult to say where your perfomance issue come in, usually collections are very quick anyway.

Maybe the issue is with the SaveData and not with the updating of the collection.

Helpful resources

Announcements
thirdimage

Power Automate 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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,015)