Hi,
I'm fairly new to power apps, with this being my first proper attempt at a real-world app. Unfortunately, I've encountered a problem that has had me stumped for hours. Hopefully I can explain this well enough that you could help me solve it.
I am creating a custom timesheet solution for our company. Occasionally an employee might need to spend 30 minutes clearing out their van at home or carrying out some other task that doesn't fit into their workday. In these cases, the employee should still "clock out" when they leave the site, but they have a toggle switch option called "Additional Time" which, if set to true, an additional 2 inputs appear "Additional Time Amount" for them to record the amount of time, and "Additional Time Reason" where they write why they required the additional time.
The editform when "no" is selected for additional time
the edit form when "yes" is selected for additional time
I've been through a few hurdles with this solution so far, but I feel like I'm finally nearing the finish line. Here's what I've done so far:
- If the user toggles Additional Time to "Yes" then I want the 2 additional inputs to be displayed. If it's set to "No" then I want them hidden. I have added this code to the "Visible" property of the data cards for the 2 inputs (Additional Time Amount, Additional Time Reason):
Toggle6.Value
- If the user changes the toggle (Additional Time) to "Yes", and fills information into the 2 related inputs (Additional Time Amount, Additional Time Reason), but then changes the toggle to "no" (perhaps they made a mistake) then I don't want the app still sending the data for "Additional Time Amount" and "Additional Time Reason", so I added the following code to clear the inputs using the "OnUncheck" for the Toggle:
Reset(DataCardValue5);
Reset(DataCardValue6);
- If the user is not entering additional time, and the "Additional Time Amount" and "Additional Time Reason" inputs are hidden, then I do not want them to be "Required", on the other hand, if they toggle "Yes" then I do want the 2 additional inputs to be required, so I added this code to the 2 inputs under "Required":
If(
Toggle6.Value = true,
true,
false
)
At this point I thought, this is great, working perfectly! But after some testing, I realised I had a few more things to solve.
If the user submits a timesheet that has the toggle for "Additional Time" set to "Yes" and has filled in the "Additional Time Amount" and "Additional Time Reason" but later goes back and changes the "Additional Time" toggle to "No", the data in the "Additional Time Amount" and "Additional Time Reason" inputs still remain on the table, even though the "Additional Time" field states "No", to solve this (which took hours of googling) I came up with the below mishmash of code from various resources, this code was added to the "OnUncheck" of the "Additional Time" toggle :
Reset(DataCardValue5);
Reset(DataCardValue6);
Patch(
Timesheets,
LookUp(
Timesheets,
ID = DataCardValue8.Text
),
{
'Additional Time Amount': Blank(),
'Additional Time Reason': Blank(),
'Additional Time': false
}
);
I think I've hit it out of the park, it's working perfectly! Except it isn't. This is a real outlier, but bare with me:
- The user submits timesheet with "Additional Time" toggled "Yes" and fills in the "Amount" and the "Reason" - Works perfectly
- The user made an error, they entered "Additional Time" for the wrong date, so they go in and toggle "Additional Time" to "No" - Works perfectly, data is cleared from both inputs and the "Additional Time" field is set to false
- The user realised that they DID mean to have additional time on this timesheet (now we're at 1 submission and 2 edits). So they go back in to edit the timesheet, flick the toggle to "Yes" and enter data into the 2 additional fields, they click save and this happens: https://streamable.com/3fx0kh (video)
If you notice, when I hit "Save" about 27s into video and it loads the "detail screen" the data I entered briefly flashes up but then disappears. It is not saved in the table either.
Sorry for the long post, if you have any insight as to why this is happening I would be very grateful for your advice! If I've done this a horrible way and you think there is a better way then I am also open to suggestions!