cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Community Champion
Community Champion

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...

Highlighted
Community Support
Community Support

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
Frequent Visitor

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

Community Champion
Community Champion

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
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (4,566)