cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PhilipS
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
v-xida-msft
Community Support
Community Support

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
v-xida-msft
Community Support
Community Support

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

Worked like a charm, thank you sir!

@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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,160)