Updating sum of subform

Updating sum of subform

I encountered another problem for updating of sum of fields in a subform.


on a main form (Make_claim), I have a dynamic drop down (approved_budget_purpose) list to which filters the the items display in a subform (expense_claim_history1). 

In the subform, I have a field "expense_amount1", which i want to total up in the field " total_expense_claimed1" in the main form.

In my drop down list, I have 2 items 
1) Buddha Day
2) Mother's Day

When I choose Budhhas Day, the subform will be populated with 1 item as below
1) expense amount: 4,000

When I choose Mother's day, the subform will be populated with 3 items as below
1) expense amount: 4,000
2) expense amount: 2,000
3) expense amount: 3,500


Scenario 1
Step 1 -> Choose Buddha Day in dropdown list
The total_expense_claimed1 = 4,000 (as expected)

Step 2 -> Change to Mother's Day in the dropdown list
The total_expense_claimed1 = 13,500 (I am expecting 9,500)

Step 3 -> Change to Buddha Day in the dropdown list
The total_expense_claimed1 remains 13,500 (It does not change to 4,000)

From then on, no matter what i choose on the dropdown list, the total_expense_claimed1 remains 13,500, although the subform is displaying the correct no. of items as expected for both choices in the drop down.

Scenario 2
Step 1 -> Choose Mother's Day in dropdown list
The total_expense_claimed1 = 9,500 (as expected)

Step 2 -> Change to Buddha Day in the dropdown list
The total_expense_claimed = 13,500 (I was expecting 4,000)

Step 3 -> Change to Mother's Day in the dropdown list
The total_expense_claimed remains 13,500 (It does not change to 9,500)

From then on, no matter what i choose on the dropdown list, the total_expense_claimed remains 13,500, although the subform is displaying the correct no. of items as expected for both choices in the drop down.


My code is as below, triggered by user input of approved_budget_purpose (i,e. Budhha Day, Mother's Day)

  1. clear expense_claim_history1;
  2. row1 = Make_claim.expense_claim_history1();
  3. //
  4. expense_history = Make_claim[claim_type == "Expense" && approved_budget_purpose == input.approved_budget_purpose && pv_no != ""];
  5. for each  expense in expense_history
  6. {
  7. row1.pv_no=expense.pv_no;
  8. row1.expense_amount1=expense.total_cost;
  9. //
  10. subformrow = Collection();
  11. subformrow.insert(row1);
  12. input.expense_claim_history1.insert(subformrow);
  13. }
  14. tot = 0.0;
  15. for each  rec in input.expense_claim_history1
  16. {
  17. tot = tot + rec.expense_amount1;
  18. }
  19. input.total_expense_claimed1 = tot;
  20. // input.total_expense_claimed1 = expense_claim_history1.sum(expense_amount1);


I have been trying to resolve this for 2 hours...

Can anyone help?