I'm working on a time input manager application. In order to limit a user entering more than 8 hours total for a few projects on a given date, I'm applying the aggregate function in form validation to sum the total number of hours for a given date+user.
The problem I just found was in
editing an entry for a given date. This may best be explained with a simple example:
Let's say a user has two projects for some date. Project A has 6 hours and Project B has 2 hours (totaling 8). Now let's say his manager wants to decrease Project A to 5 hours. The form validation aggregate function then sums the existing records Project A at 6 + Project B at 2 AND the inputted value of 5 for Project A (in process of being edited) resulting in 13 hours - thus invoking a validation error and canceling submit.
The workaround I came up with is identify the current record being edited (by project name) in the validation script and subtract the hours from the aggregate record function before testing if the sum total is 8 or less. This works, but it would be handy to have some general ability to detect if a record is open for editing and allowing the code to take some different actions based on the "open for edit flag".