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

Using ForAll and Patch for a Gallery

Hello,

 

I am trying to use ForAll with Patch to enter a filtered Gallery into a SQL Database.

 

Here is the code for the submit button I am using:

ForAll(PartialGallery.AllItems,Patch('[dbo].[Daily]', {RecordID:RecordID}, {AssignedMilkHauler:AssignedMilkHauler,Trailer:Trailer,ManifestNbr:ManifestNbr}))

 

When I hit the button, it looks like Powerapps is trying to do something, but once it finishes I don't see any of my data being entered nor do I see an error message on the button.

 

If anyone has successfully done this and could help me out, I would greatly appreciate it.

 

Thank you,

Ben

3 REPLIES 3
Gargoolgala
Level 8

Re: Using ForAll and Patch for a Gallery

Hi bhayden,

 

I have somthing I thin kis similar - I have a gallery with a checkbox control.  When I press the onselect of a button I run this command

 

ForAll(Filter(DeviceList.AllItems,DeviceName.Value=true),Patch(CustomerDeviceList, Defaults(CustomerDeviceList),{CustomerID:SelectedCustomer.ID,DeviceID:ID,Qty:DeviceQty.Text,Title:Title,DeviceType:DeviceType.Text}))

 

 

It looks like you missed the Defaults(CustomerDeviceList) which tells the Patch to add a new record to the table.

 

It will select only the checked items in the DeviceList gallery and patch them to my CustomerDeviceList with the values for each record in the gallery.

 

I als odo a removeif first in case the record can be edited/updated later and I do not want duplicates

 

RemoveIf(CustomerDeviceList,CustomerID=SelectedCustomer.ID And DeviceType=DeviceListDD.Selected.Value)

 

This is a Sharepoint list but you can substitute the sharepoint list for you SQL table.

 

Not sure if this is exactly the same but I hope it gives you something to build off.

bhayden
Level: Powered On

Re: Using ForAll and Patch for a Gallery

Thank you for the response. This patch is actually only for editing existing records, which is the reason that I did not put in the Defaults() function. In case I misread something, you are using RemoveIf() to edit exisitng records?

Gargoolgala
Level 8

Re: Using ForAll and Patch for a Gallery

you will not need the removeif as you are only editing.

Helpful resources

Announcements
thirdimage

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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (3,864)