Function not working for On Delete/On Success to update a running total

Function not working for On Delete/On Success to update a running total

I have the following function set up to calculate a running total of donations in a ‘donations’ form.


float totals.DonationTotal()

{

    total = 0.0;

    for each d in donations

    {

        total = (total  +  d.donation_us  *  d.exchange_rate  +  d.donation_mxn);

    }

    return total;

}

The following function is invoked on the On Add/Action on Success and On Edit/On Success in the ‘donations’ form:


for each c in campaigns  [campaign_name == input.campaign_name]

{

    c.total_collected = thisapp.totals.DonationTotal();

}


The above code works fine for updating the total per campaign in the ‘campaigns’ form for on add/on edit.

However I can’t get the function to recalculate the total if a record is deleted from the donations form.  I tried the above code in On Delete/On Success but it doesn’t work. If I test executing the function after deleting a record it calculates the total fine, but the total in the campaigns form isn’t updated with the correct figure until a new donation is added, or a current donation is edited.  I need the total to update as a record is deleted.

Any advice would be greatly appreciated! 

Thanks, Lara