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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (55,677)