I have an invoice database, and when an invoices balance reaches zero or less, the sales rep who owns that invoice receives their commission. In order for me to track the date when Sales Reps earn their commission on each invoice, after a payment is posted against an invoice, if the new balance is <= 0, then the current date is recorded within it.
The Balance is a calculated field, and the date is a simple date field.
I have an add payment script, which adds a new payment, calculates the new total payments sum, records it, and then sets the 'CommissionEarnedDate' field to the current date depending on the new balance. The problem is that it does not seem like the balance calculation field is updating properly before the script tests to see if the balance is <= 0.
But if I run the script to set the 'CommissionEarnedDate' field manually, it works correctly. Why isn't the Balance calculation not updating untill all scripts have finished running. Is there a way to force this calculation to be evaluated during the script so that the date can be set properly.
Thanks