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()?
ForAll(Collection1, UpdateIf(Collection2, RecID = Coll1.RecID, Coll1.currentRecord))
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:
1) Patch can be used to modify or create a set of records in a data source. The syntax is Patch( DataSource, BaseRecordsTable, ChageRecordTable1, [, 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:
ForAll( Table, Formula )
But the part UpdateIf(Collection2, RecID = Coll1.RecID, Coll1.currentRecord) returns not a formula, but a table. So ForAll function won't work.
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
.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.
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.
Fill out a quick form to claim your user group badge now!
Find out where you can attend!
Features releasing from October 2019 through March 2020
Learn how to build the business apps that you need.