cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Community Support
Community Support

Re: patch forall gallery control

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

Re: patch forall gallery control

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

bmarshall
Frequent Visitor

Re: patch forall gallery control

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}))

Community Support
Community Support

Re: patch forall gallery control

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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (6,450)