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

Default Value on Toggle

Hi, 

I'm farely new to powerapps but am involved in building an app for my University professor to enable him to schedule the work of his apprentices more easily.

Skärmavbild 2019-06-05 kl. 12.07.31.png


The apprentices receives this gallery of scheduled work shifts. If the apprentice is available for work they just chech the toogle for that specific shift and the information is saved in an Azure database.

The problem is that when the powerapp is turned off, the toggle value is immediately turned to false. To solve this, I created a column in the database called ToggleValue, and whenever the Toggle is checked I use Patch to change the ToggleValue for that specific record to "True" and "False" when unchecked:

Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]';ID = ThisItem.ID);{ToggleValue: "True"}) 
Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID);{ToggleValue: "False"})

 

I then set the Default value of the toggle to:

If(ThisItem.ToggleValue = "True"; true; ThisItem.ToggleValue = "False"; false)

This works fine when I check the toggles, except when I check the one connected to the first record in the gallery. When doing that it seems like a chain event is created that checks every single toggle.

Any ideas on why this is occurring? Any suggestions on altering the code to make this work?

Thanks,
Philip. 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Default Value on Toggle

Hi @PhilipS ,

Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned.

 

Please consider remove the formulas from the OnCheck property and OnUncheck property of the Toggle control, instead, set the OnSelect property to following:

If(
   Toggle1.Value = true;
   Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID); {ToggleValue: "True"});
Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID); {ToggleValue: "False"}) )

set the Default property of the Toggle control to following:

If(ThisItem.ToggleValue = "True"; true; false)

 

If the issue still exists, please consider use the UpdateIf function to update the ToggleValue instead of using Patch function. Set the OnSelect property of the Toggle control to following:

If(
   Toggle1.Value = true;
   UpdateIf('[dbo].[Timeedit_data]'; ID = ThisItem.ID; {ToggleValue: "True"});
   UpdateIf('[dbo].[Timeedit_data]'; ID = ThisItem.ID; {ToggleValue: "False"})
)

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
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

2 REPLIES 2
Community Support Team
Community Support Team

Re: Default Value on Toggle

Hi @PhilipS ,

Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned.

 

Please consider remove the formulas from the OnCheck property and OnUncheck property of the Toggle control, instead, set the OnSelect property to following:

If(
   Toggle1.Value = true;
   Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID); {ToggleValue: "True"});
Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID); {ToggleValue: "False"}) )

set the Default property of the Toggle control to following:

If(ThisItem.ToggleValue = "True"; true; false)

 

If the issue still exists, please consider use the UpdateIf function to update the ToggleValue instead of using Patch function. Set the OnSelect property of the Toggle control to following:

If(
   Toggle1.Value = true;
   UpdateIf('[dbo].[Timeedit_data]'; ID = ThisItem.ID; {ToggleValue: "True"});
   UpdateIf('[dbo].[Timeedit_data]'; ID = ThisItem.ID; {ToggleValue: "False"})
)

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
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

PhilipS
Level: Powered On

Re: Default Value on Toggle

Worked like a charm, thank you sir!

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Demo Extravaganza Championship Voting Open

Voting Ends: October 30, 2019!

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

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

Top Kudoed Authors
Users Online
Currently online: 182 members 4,833 guests
Recent signins:
Please welcome our newest community members: