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

Use a toggle to change a field

Hi,

 

I want to add a Toggle to change a field from Y to N.

I'm new to PowerApps need some help filling all the necessary function fields

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Use a toggle to change a field

I'm not exactly sure what you want to do but you would need to use the default property of the toggle. The usual is parent.default.
15 REPLIES 15
Highlighted
PowerApps Staff AKotb
PowerApps Staff

Re: Use a toggle to change a field

Hi,

 

do you mean changing the content of a Label from Y to N ?

in that case you can do that easily by changing the text rule of the label to something like this

 

If (Toggle1.Value, "Y", "N")

where Toggle1 is the name of the toggle control

NigWatson
Level: Powered On

Re: Use a toggle to change a field

No,

 I want to use the toggle to change a data field in the data source from N to Y.

 

Thanks

Super User
Super User

Re: Use a toggle to change a field

Hi @NigWatson,

Set Toggle properties

OnCheck - Patch(datasource,baserecord,{datafield:”Y”})

OnUncheck - Patch(datasource,baserecord,{datafield:”N”})

baserecord would be be something like LookUp(datasource, ID=Gallery1.Selected.ID) or 

LookUp(datasource, ID=ThisItem.ID) if the toggle was inside a gallery.

NigWatson
Level: Powered On

Re: Use a toggle to change a field

Thanks Drrickryp,

 

But I don't understand baserecord

 

Could you please explain  LookUp(datasource, ID=Gallery1.Selected.ID) ?

Super User
Super User

Re: Use a toggle to change a field

The patch function consists of three components: the datasource being patched,  the base record being edited and the item being changed. It would be helpful if you could post a screenshot of the screen where you are placing the toggle so I could better explain it to you.  If you want to visualize it imagine a spreadsheet that contains a Table, thats the datasource.  The row inside of the table is the base record and the field in that row is the datafield.  Please watch the You Tube about the Patch function to understand how it works. 

In your case, I want to use the toggle to trigger the Patch function and make the change you want in your datasource.  

NigWatson
Level: Powered On

Re: Use a toggle to change a field

Hi Drrickryp,

Here are shots of the App's edit screen and it's data source:

 

EditScreen.png

 

DataSource.png

 

 

 

Super User
Super User

Re: Use a toggle to change a field

Ok, This looks like it could be from an app developed from an Excel spreadsheet, Is that correct?  If  you are using an edit form, then you won't need to use the Patch function.  Please post a screenshot where you mouse over the red x so that I could see the error message you are getting.

NigWatson
Level: Powered On

Re: Use a toggle to change a field

Yes, that's correct the app was generated from a speadsheet.

Here's the error message.

error.png

Super User
Super User

Re: Use a toggle to change a field

Ok get out of preview mode by hitting f5.  Then click on the card containing the toggle but not the toggle itself.  Open the dropdown box in the upper left hand side of the screen and find the Update property.  Please let me know what it says.  

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 48 members 4,353 guests
Please welcome our newest community members: