cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Stijn007
Advocate III
Advocate III

Patch to multiple rows

Halllo,

 

I can not figure out this problem. 

 

I have a gallery "1 " with a checkbox inserted. when the user checks a box , it's added to a collection. 

 

On a other page , i have a gallery "3"  with the items property set to that collection. ( only the items that the users has checked from gallery "1" ) 

I want to patch a text value to all items in that gallery. 

This is what i have , but nothing happens: 

ForAll(Gallery3.AllItems ; Patch('B-Transport Operations'; {'Naam_B-TO_tekst': Label4.Text }))

 

gallery 3 contains the items that are checked from gallery "1"

B-Transport Operations = Sharepointlist 

'naam_B-TO_tekst is the textcolumn in sharepoint

Label.4Text is the value that has to be patched to all items of gallery 3

 

1 ACCEPTED SOLUTION

Accepted Solutions

Following formula is working: 

 

ForAll(RenameColumns( Filter('B-Transport Operations'; Selectie = "JA" );"ID" ; "EID") ; Patch('B-Transport Operations' ; LookUp('B-Transport Operations'; ID = EID ); {'Naam_B-TO_tekst': Dropdown2.Selected.Value }))

 

 

Thank you all for the help. 

View solution in original post

8 REPLIES 8
Doug_Apicella
Advocate II
Advocate II

Hi Stijn

 

It looks like there is another thread that addresses this. You can use Collect instead of Patch. Here is the link to the thread:

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Patch-all-items-in-Gallery/m-p/396014/highli... 

 

Thanks!

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

i tried it , but in the sharepointlist , new records are created ( added )

I want to selected items to be changed. 

 

My formula is now :

ForAll(Gallery3.AllItems ; Collect('B-Transport Operations'; {'Naam_B-TO_tekst': Label4.Text }))

 

@Doug_Apicella 

 

svijay_001
Microsoft
Microsoft

Alternatively if you want Patch, you could use a below implementation : 

 

ForAll(Gallery1.AllItems,Patch(IceCream,First(Filter(IceCream,Flavor=Label1.Text)),{Quantity:<Value>}))

The Parameters are explained 
Gallery1 - is the Destination Gallery to which items needs to patched to
IceCream - Collection 

<Flavor=Label1.Text> - To get the specific row in the loop. You can modify the condition based on the requirement

  • Flavor - One of the column in the Collection 
  • Label1.Text - The value of the column

Quantity - The Column of the collection that you would like to Update

 
 

 

Hi @Doug_Apicella 

This is one of the most common errors seen with the Patch() function.  It requires three elements,

  1.  The datasource being patched, can be an original connector datasource or a collection but it must be a table.
  2. The row in the datasource being patched.  If it is a new item being added then this element will be Defaults(TableName), if it is for modifying an existing row then usually it will be a formula that results in a row such as Lookup(TableName, ID=ThisItem.ID)
  3. The specific fields in the row being patched enclosed in curly brackets that indicate the columnname followed by a ":" then the  value being patched. {ID: Textbox1.Text} or {ContactName:Dropdown1.Selected.Value}

Most of the problems are forgetting to put in the row being patched, or having the incorrect column name.  This frequently occurs with SharePoint because the actual column names may not be the same as the name displayed in PowerApps.  Finally, if a collection is being used for a patch with the ForAll() function, it is helpful to disambiguate the field in the formula used to identify the row.  I have found that a good way is changing the name of the field in the collection using the RenameColumns function, then the new name can be used in the Lookup() formula.    

ScottShearer
Super User
Super User

@Stijn007 

I believe this video from Shane Young directly addresses your issue.

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

Thanks for the support, 

 

I tried following formula, but it patches only the first item. 

 

ForAll(Gallery1.AllItems ; Patch('B-Transport Operations' ; First(Filter('B-Transport Operations' ; Selectie = "JA")); {'Naam_B-TO_tekst': Dropdown2.Selected.Value }))

 

I have created a textcolumn and when  an item is selected, it patches "JA" to the item. 

a second gallery ( gallery1)  is displayed with the selected items ( filter all items where the textcolumn "selectie" = "JA" 

Following formula is working: 

 

ForAll(RenameColumns( Filter('B-Transport Operations'; Selectie = "JA" );"ID" ; "EID") ; Patch('B-Transport Operations' ; LookUp('B-Transport Operations'; ID = EID ); {'Naam_B-TO_tekst': Dropdown2.Selected.Value }))

 

 

Thank you all for the help. 

Justcru
Frequent Visitor

Hello there,

I tried adapting your ForAll to my Situation and the only thing it does for me is creating empty rows with the patch-value in it for the amount of records which should be patched.

E.g.: 3 records should be patched but instead I get 3 new rows with the update value but otherwise they are empty.

This is my statement:

ForAll(
RenameColumns(Filter([@OKR_KeyResult];ObjectiveID=DataCardValue28.Text);"crb68_objectiveid";"newObjectiveID");Patch([@OKR_KeyResult];LookUp([@OKR_KeyResult];ObjectiveID=newObjectiveID;{ObjectiveNummer:DataCardValue3_1.Text})))

 

Any ideas or did you encounter the same problem maybe?

 

Best regards

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,811)