I was excited to see bulk update promoted in the latest version. However there is no single example of the syntax needed in the documentation. I tried some obvious alternatives but could not make it work. Please, if you have taken so much effort to include the feature, make a little more effort to show us how it works.
Solved! Go to Solution.
We are working on improving the documentation for all of this. The latest can always be found here:
Patch:
https://powerapps.microsoft.com/en-us/tutorials/function-patch/
ForAll:
https://powerapps.microsoft.com/en-us/tutorials/function-forall/
There are multiple ways to use multi-patch. Here's one way:
Patch(datasource, table)
The second parameter specifies a table of records to push into 'datasource'. Each row in 'table' must have at least a value for the primary key of 'datasource' -- that's how Patch will find the records in 'datasource' that need to be patched. The rest of the fields in each row in 'table' specify the values to be pushed into the corresponding row in 'datasource'. Example:
Patch(Cars, Table( { Id: 12, Brand: "Audi", Model: "A7" }, { Id: 24, Brand: "Volvo", Model: "S6" } ))
The ForAll function allows for the evaluation of an expression on every row of a data source. The expression can be side-effect free, such as a simple Sum, or it can be a possibly chained expression consisting of imperative actions, such as Collect. The ForAll invocation will assemble a table of results, one per expression at every row. Some examples:
ForAll(Squares, Sqrt(Value))
ForAll(Squares, Collect(datasource, { Square: Value }))
ForAll(Cars, If(Brand = "Volvo", Collect(VolvoCars, { Name: Model, Year: Year })))
I hope this helps.
I just posed the same question on the forum 🙂 It goes to show you how popular this feature is--it will be a game changer if I can get it to work.
I can publish a Camtasia video for the forum if I can get some examples of the syntax first. @rgruian, can you elaborate on the bulk Patching?
Absolutely. It is the last piece of the puzzle to create functional ocasionally connected mobile apps.
The blog was very esplicit about the new capabilities.
"Finally, one of the reasons you gave us for needing iteration was the bulk update of data. And ForAll can be used for that. But as we think it may be common, we also added the ability to use the Patch function on a set of records instead of just modifying one record at a time."
We are working on improving the documentation for all of this. The latest can always be found here:
Patch:
https://powerapps.microsoft.com/en-us/tutorials/function-patch/
ForAll:
https://powerapps.microsoft.com/en-us/tutorials/function-forall/
There are multiple ways to use multi-patch. Here's one way:
Patch(datasource, table)
The second parameter specifies a table of records to push into 'datasource'. Each row in 'table' must have at least a value for the primary key of 'datasource' -- that's how Patch will find the records in 'datasource' that need to be patched. The rest of the fields in each row in 'table' specify the values to be pushed into the corresponding row in 'datasource'. Example:
Patch(Cars, Table( { Id: 12, Brand: "Audi", Model: "A7" }, { Id: 24, Brand: "Volvo", Model: "S6" } ))
The ForAll function allows for the evaluation of an expression on every row of a data source. The expression can be side-effect free, such as a simple Sum, or it can be a possibly chained expression consisting of imperative actions, such as Collect. The ForAll invocation will assemble a table of results, one per expression at every row. Some examples:
ForAll(Squares, Sqrt(Value))
ForAll(Squares, Collect(datasource, { Square: Value }))
ForAll(Cars, If(Brand = "Volvo", Collect(VolvoCars, { Name: Model, Year: Year })))
I hope this helps.
Neat!
Hi MRCL:
You may refer to my latest post:
Useful Features of PowerApps (15): Multiple Records ....
for your reference if you wish, for your reference.
TQ
Where exactly do we type in the 'Patch' formula in the GUI? Thanks!
Hi @Anonymous
Maybe my Useful Features of PowerApps ; Multi-Patch and ForAll is not clear.
In order to trigger Patch or ForAll, you can always use them with:
- Button. OnSelect
- Timer1.OnTimerEnd
- and any other behavior formula in which you OnSelect, OnChange, OnCheck, OnUnCheck, and even If, UpdateIF.
Hoep this helps.
Thanks so much hpkeong! That totally cleared things up for me 🙂
RECIPE: ADDING MULTIPLE NEW RECORDS IN A COLLECTION TO A DATASOURCE
Use "Collect" instead of "Patch" to append multiple new records to an existing datasource. The collection has to have the same field names as the datasource.
The format is:
Collect ( DataSourceName , CollectionName )
EXAMPLE
If MyFruitCollection is a collection with the following records:
{ FruitID : 7, FruitName: "Apple"},
{ FruitID : 8, FruitName: "Banana"},
{ FruitID : 9, FruitName: "Pear"}
And MyFruitDataSource a datasource containing these records:
{ FruitID : 1, FruitName: "Grape"},
{ FruitID : 2, FruitName: "Orange"},
{ FruitID : 3, FruitName: "Tomato"}
Then the call:
Collect ( MyFruitDataSource, MyFruitCollection )
will update MyFruitDataSource to be:
{ FruitID : 1, FruitName: "Grape"},
{ FruitID : 2, FruitName: "Orange"},
{ FruitID : 3, FruitName: "Tomato"},
{ FruitID : 7, FruitName: "Apple"},
{ FruitID : 8, FruitName: "Banana"},
{ FruitID : 9, FruitName: "Pear"}
... You would think that:
Patch ( MyDataSource , Defaults ( MyDataSource ) , MyCollection )
would work, but it doesn't.
A constructor for this Patch signature hasn't been implemented in PowerApps. Rather, you get a type error where Patch is expecting a Record in the third argument but gets a Table (MyCollection) instead.
User | Count |
---|---|
125 | |
87 | |
86 | |
75 | |
69 |
User | Count |
---|---|
215 | |
181 | |
139 | |
97 | |
83 |