cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bmarshall
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
v-micsh-msft
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
v-micsh-msft
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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,111)