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:
Toggle6.Value
Reset(DataCardValue5);
Reset(DataCardValue6);
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:
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!
Very good! Yes, I see a lot of people that use Patch to patch a form and they don't need to (and in fact, you lose most all of the features of a Form when you do). There is no need. Forms are very flexible in their operation as long as you know all the places to do things.
I'd recommend to carve some time out and watch my video on Forms Plus - everything you ever wanted to know about EditForm and some ways to use them that you may not have even know. It's a long one, but very comprehensive. You will see that when you use them, things become much simpler.
Just post back here when you have issues. Don't spend too much time chasing ghosts.
Thank you for the quick, detailed reply Randy.
I have made the changes you have mentioned (apart from changing the reset on toggle - I'll be looking into how to change this to be considered "on submit" this evening), and everything is working perfectly!
In regards to using patch - this is what happens when you've spent 3 hours trying to fix something that you don't entirely understand, and have turned to desperately scouring google at 2am for something that could help. I have a lot more to learn, starting with a deeper dive into forms!
Thanks again! 👍
A couple things to consider:
1) Don't reset your Additional Time and Amount columns on the toggle. This could be frustrating to a user because they might have entered something, then toggled the additional time off by mistake, turn it back on and all is gone. Instead consider this as the submit time. This would also resolve the issue of editing a record.
2) Why are you using the Patch statement if this is a form? You should be using SubmitForm on the form.
Now:
- Change the Required property on the two additional datacards to Toggle6.Value You don't need all the If true true false stuff. The toggle will either be true or false already.
- On the Update property of the two datacards, set the formula to the following:
If(Toggle6.Value,
yourDataCardValuexControlName.Text,
Blank()
)
You WILL need to make sure that the Formula level error Management feature is turned ON in your advanced settings for this to work.
Also, as I give the above formula as a general formula you need for your Update property, you also appear to have a dropdown in the one column, so the actual formula will need to be adjusted to that control and to the underlying data column type.
- Discard using Patch and use SubmitForm on your form : SubmitForm(yourForm)
As for the item disappearing in the detail, the question would be, for both of the EditForm and the Display form, what is the Item property?
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional