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

patch forall gallery control

I have a screen that has a dropdown of states and when a state is selected a gallery is filtered to the selected state.  I need to update an Azure SQL Server database table with the toggle (on/off or 1/0) for each record in the gallery.  Right now it is updating the wrong record, always the one above the one that is changed. The code on the submit button is this: 

 

ForAll(Gallery3.AllItems, Patch([dbo].[DisasterAreas], [dbo].[DisasterAreas], {countyselected: tglcountyselected.Value}))

 

DisasterAreas is the table to be updated and countyselected is the boolean field that I want to update.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @bmarshall,

 

The patch function here:

Patch('[dbo].[DisasterAreas]', [dbo].[DisasterAreas], {countyselected: tglcountyselected.Value})

should have some problems finding the proper record.

Basically, the second part is the record you are trying to update with, but here you are using the whole table (not a record) as the parameter, I don't think that would work. 

 

For the Update that you would like to achieve, could you please share more details about that?

If the toggle is out the gallery control, and once button pressed, it will update all the filtered records in Gallery with the value of toggle into SQL Table, then I think the formula could be written in the following way:

Clearcollect(NewData, Gallery.Allitems);
Forall(renamecolumns(NewData, "Id","NewId"),
       patch('[dbo].[DisasterAreas]',first(filter('[dbo].[DisasterAreas]',Id=MewId)),{countyselected:tgcounty.Selected.Value})
           )

If I have any misunderstandings, please post back.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Community Support
Community Support

Hi @bmarshall,

 

The patch function here:

Patch('[dbo].[DisasterAreas]', [dbo].[DisasterAreas], {countyselected: tglcountyselected.Value})

should have some problems finding the proper record.

Basically, the second part is the record you are trying to update with, but here you are using the whole table (not a record) as the parameter, I don't think that would work. 

 

For the Update that you would like to achieve, could you please share more details about that?

If the toggle is out the gallery control, and once button pressed, it will update all the filtered records in Gallery with the value of toggle into SQL Table, then I think the formula could be written in the following way:

Clearcollect(NewData, Gallery.Allitems);
Forall(renamecolumns(NewData, "Id","NewId"),
       patch('[dbo].[DisasterAreas]',first(filter('[dbo].[DisasterAreas]',Id=MewId)),{countyselected:tgcounty.Selected.Value})
           )

If I have any misunderstandings, please post back.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

This worked.  Thanks for the help v-micsh=msft.  Here is the final code that was used:

 

ClearCollect(NewData, Gallery3.AllItems);
ForAll(RenameColumns(NewData, "DisasterAreasId","NewId"),
Patch('[dbo].[DisasterAreas]',First(Filter('[dbo].[DisasterAreas]',DisasterAreasId=NewId)),{countyselected:tglcountyselected.Value}))

Hi @bmarshall,

Thanks for the update.

Beisdes, if it is convenient, please accept it as the solution to this question, which would help the others when may have the same problem to find the workable way easier.

 

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (11,504)