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

Toggle patch to SQL works on BrowseGallery but not on DetailsScreen1

Hi All

 

Please forgive my rudimentary speak (I've only started learning powerapps today)

 

I'm trying to build an app where staff can grab the next available PO number from a SQL table

 

I've added a toggle for the PO status (cancelled/not cancelled) and managed to patch it so it writes back to the SQL table, but it only works if the toggle is on the BrowseGallery screen. I'd really like to have it on the Details Screen though, but when I do 'ThisItem' doesn't go red in the formua bar?

Can we not use 'ThisItem' from the details screen?

Are there any other alternatives ways to do this?

 

Any help would be appreciated

Regards

Vicky

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Toggle patch to SQL works on BrowseGallery but not on DetailsScreen1

Hi Vicky,

'ThisItem' is valid syntax on a details form in a detail screen, provided that the control where you call the Patch function is contained within a Card that's inside the form. You can use the tree view in the left hand pane to find out exactly where a control is located.
To add controls to a Card, it's necessary to first unlock the card using the option in the Advanced section of the card.
By default, the data source of a detail form is set to BrowseGallery1.Selected. You can find this out by looking at the Item property of the detail form. Therefore, the formula you can use to patch the current record on a detail form will look something like this.

Patch('[dbo].[MobilePOLog]',
          BrowseGallery1.Selected,
         {StatusColumn: Toggle3.Value}
)

Hope that helps.

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Toggle patch to SQL works on BrowseGallery but not on DetailsScreen1

Hi Vicky,

'ThisItem' is valid syntax on a details form in a detail screen, provided that the control where you call the Patch function is contained within a Card that's inside the form. You can use the tree view in the left hand pane to find out exactly where a control is located.
To add controls to a Card, it's necessary to first unlock the card using the option in the Advanced section of the card.
By default, the data source of a detail form is set to BrowseGallery1.Selected. You can find this out by looking at the Item property of the detail form. Therefore, the formula you can use to patch the current record on a detail form will look something like this.

Patch('[dbo].[MobilePOLog]',
          BrowseGallery1.Selected,
         {StatusColumn: Toggle3.Value}
)

Hope that helps.

View solution in original post

VickyW
Level: Powered On

Re: Toggle patch to SQL works on BrowseGallery but not on DetailsScreen1

Not in a year of gogling would I have figured that out!
Thank you so much 🙂

 

One last question before I go - when I press the toggle to yes, the 3 dots go across the top of the screen, and my SQL table updates, but then the toggle mysteriously moves back to the 'no'position?

 

That means it then has to be pressed twice (back to yes, and then to no) to get it to update the SQL table back to a 'no'

Is it meant to behave like that?

--------------

EDIT: woops my bad. I assumed it was leaving the table correct, and it was only the toggle switch that apreared in the wrong position -  but when the toggle is pressed it's actually updating the table to true, and then quickly back to false, just as the same as the toggle itself.

VickyW
Level: Powered On

Re: Toggle patch to SQL works on BrowseGallery but not on DetailsScreen1 / also toggle resetting

Oooof it's taken all night & morning & reading endless posts to figure how to stop the toggle resetting after the form is submitted, so hopefully this will help someone else:

 

1. Do what @timl says and put the toggle imside a datacard on the DetailForm1

2. Set the toggle Default to

If((ThisItem.StatusColumn) = true,true,false)

Replace 'StatusColumn' with the name of boolean column you wish the toggle to represent

 

3. Set the toggle OnSelect to 

Patch('[dbo].[MobilePOLog]', BrowseGallery1.Selected, {StatusColumn: Toggle1.Value})

Same again, replace 'StatusColum' and dbo name for your own

 

This should keep your toggle in sync with your DB, and your DB in sync with your toggle! 🙂

I think!

 

 

 

 

Helpful resources

Announcements
thirdimage

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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,002)