cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
i-gonak
New Member

Changing data with toggle control

Hello everybody,

 

so I'm trying to change the underlying data with a toggle control: toggle on --> field = 0, toggle off --> field = 1.

 

This is what I have so far:

OnCheck:

Patch(import_countries; First(Filter(import_countries; BEZ_ENG = ThisItem.BEZ_ENG)); { IMPORT_BLOCKED: 0 })

OnUncheck:

Patch(import_countries; First(Filter(import_countries; BEZ_ENG = ThisItem.BEZ_ENG)); { IMPORT_BLOCKED: 1 })

Default:

If(ThisItem.IMPORT_BLOCKED = 0; true; false)

 

The bevahiour I get is quite confusing. When I toggle once, it sometimes switches forever, sometimes it switches just back, i.e. toggle is on, I click on it, it gets off and on again immediately. I can't find a mistake in my code 😕

 

I tried to google and found very similar topic and the code looks the same:

https://powerusers.microsoft.com/t5/General-Discussion/Patching-Sharepoint-list-from-checkbox/td-p/8...

 

3 REPLIES 3
Super User
Super User

Re: Changing data with toggle control

Hello i-gonak,

I think the issue is the Default property. You can test it.
If you erase the expression from the default property, the toggle will not change.
You patch the value IMPORT_BLOCKED that you use in the if statement in the default property. So every time that you patch the value it refreshes the Default value and the toggle changes.
It's like a circle. 

i-gonak
New Member

Re: Changing data with toggle control

I already tried to "debug" a bit and of course deleted Default-Function first. Please look at the gif to see the behaviour. Sometimes it works, sometimes toggle switches but with wrong value, sometimes it "jumps" back again.

 

The reason I tried to use this Default-Function is that I have have different values (0 or 1). So it doesn't make sense to have all toggles in the list either true or false. It has to be always dependant on the current value in the data.

Super User
Super User

Re: Changing data with toggle control

Can you add a button and add the following expression 
Button1.OnSelect = UpdateContext({vImportCountryDefault:ShowColumns(import_countries,"ID","IMPORT_BLOCKED")})
and then change the default property to
Toggle1.Default= If(LookUp(vImportCountryDefault,ID=ThisItem.ID,IMPORT_BLOCKED) = 0; true; false)
?
You can press the button and then test if you have the functionality that you need.

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Attending MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’re streaming the digital event live, or watching on-demand, claim your attendee badge to sport on your profile.

‘Better Together’ T-Shirt Contest – Winner Announced!

‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

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!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

‘Better Together’ Integration Forum Launch

‘Better Together’ Integration Forum Launch

We're launching a how-to forum where you can learn about how Power BI integrates with other Power Platform products.

Emergency Response & Monitoring Solution

Emergency Response & Monitoring Solution

Microsoft has created a regional government emergency response and monitoring solution that is built on Power Apps and Power BI.

Top Solution Authors
Top Kudoed Authors
Users online (5,244)