You could use another field so that, when your script runs the first time, you can fill this new field.
Putting an IF in your script, you can check if the new field is empty or not, then execute the remaining steps or exit the script.
The script triggers ON ENTER don't seem to capture the 'pre value'.
Do you mean the keystroke "enter" or when entering the field?
If you want to do this with triggers you probably need to do a lot more:
- use OnModify
- prevent the user from changing the field if there is already a value, let them create another transaction instead of modifying an existing one
Give the field an OnEnter and an OnExit trigger. (You can use the same script with different parameters.)
OnEnter, capture the current field value in a $$var; OnExit, compare the current field value with the $$var's value, and proceed accordingly (and don't forget to reset the $$var …)
onObjectSave trigger fires only the value is changed.
But I think it is not good that every user input changes data without the input is not saved...
Taking a step back...
From the problem and the proposed solutions, it appears you are manually managing the A: Remaining field via script and SetField.
I think you would be better off letting A;Remaining be an unstored calc which is along the lines of :
Budget - Sum(Transactions::CheckAmt)
This would filter through the Accts relationship that you already have if my assumptions on your intent are correct.
No scripts or triggers needed.
But a potentially very slow solution... updating through a scripted Set Field is superior for performance and reporting etc.
I tried the A:remaining-sum(transactions::CheckAmt) idea and it seems to work. However,--
When I change accounts the amount needs to be refreshed and new A:Remaining calculated
I tend to think that selecting the accounts table and then using set field to manually change the A:Remaining is the simplest...
Unless, you have an idea to somehow use relations and/or calculations to distribute the correct amount when the account changes?
Thanks for the idea. It is interesting....
oops... forgot to include this:
This little script seems to work well. I just need to do something similar when the Account changes as a change to an existing account.
GAAP (Generally Accepted Accounting Principles) would prohibit the changing of an account and require an 'offsetting' new entry. But, this is basically a 'single entry' accounting system so it is probably more user friendly to let them change the Account...