cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Community Support
Community Support

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

3 REPLIES 3
Highlighted
Community Support
Community Support

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

Highlighted
Frequent Visitor

Re: Default Value on Toggle

Worked like a charm, thank you sir!

Highlighted
Helper I
Helper I

Re: Default Value on Toggle

@v-xida-msft , what would be my default value if i just want to retain the value of the toggle when i press edit.  i have a toggle that says yes and no.  when i select yes and hit submit, it will be saved on the excel data as yes.  when i come back to the same record and hit edit, it would automatically come back to no.  it will not remember the previous data.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,849)