Remove last instances of subforms w/ min count of 0: calculations not updating

jordanas6135467

12-04-2016

I have an Expense Form created in LiveCycle, where a user clicks an icon button for an individual expense category (i.e. Meals, which is under form1.ExpenseReport.ExpenseType.TravelMeals) and a repeating subform (with a min instance count set to 0) is displayed for each separate category. At the end of the report is a Summary page that contains subforms (i.e. form1.Summary.MealsSumm) calculating the totals for all of the repeating subforms from each individual category (in FormCalc), and then the total of all categories are summed in the beginning of the Acknowledgment section (which is originally hidden from the form’s layout) under form1.Footer.

There are remove buttons in the subforms (i.e. form1.ExpenseReport.Expenses.Meals.MealsExpense.RemoveExpense) and the totals update when the subforms are removed.  However, if all of the subforms for one category are removed (i.e. all Meals’ expenses), and a user goes back to add another Meals expense, the form doesn’t recalculate, and the totals in the Summary and Acknowledgment sections stay at $0. However, if the user were then to click the Remove button in the Summary section for Meals (after they click the Remove button in the upper Meals expense), and then goes back and adds another expense, the totals update correctly. Unfortunately, our end-users would not know to go down to the Summary section to remove that Meals line item from the Expense as that is for internal use only. 

Therefore, I had tried putting this in FormCalc on the Mouse Down event of the Remove button (this example is on the Airfare expense):

var I=form1.ExpenseReport.Expenses.resolveNodes("Airfare[*]").length

if (I == 0) then

form1.Summary.AirSumm[*].AirTotal.rawValue == "0"

form1.Footer.Total.execCalculate()

endif

This is the click event of the Remove button (in JavaScript):

  1. this.resolveNode('Expenses._Airfare').removeInstance(this.parent.index);

if (xfa.host.version < 😎 {

xfa.form.recalculate(1);

}

And this in the Mouse Up event of the Remove button (in FormCalc):

var I=form1.ExpenseReport.Expenses.resolveNodes("Airfare[*]").length

if (I <= 1) then

    Summary._AirSumm.removeInstance(0)

    

endif

It worked in terms of removing the Airfare Summary subform when <=1 instance of the repeating Airfare subform exists, but then the overall expenses Total (in the Footer) did not update to $0 and stays as the last amount of the form1.ExpenseReport.Expenses.Airfare.Amount expense.  Even if I pull the overall expenses Total directly from form1.ExpenseReport.Expenses.Airfare[*].Amount, it still doesn’t update to $0.  I am not a developer and could use someone’s help who is fluent in either LiveCycle’s variation of JavaScript or FormCalc to see where I’m going wrong.


Thank you!!

Accepted Solutions (1)

Accepted Solutions (1)

jordanas6135467

12-04-2016

Was able to fix by modifying to the following (all on the remove button of Airfare Expense), and it worked. Wanted to post in case this helps anyone in the future.

 

Mouse Down (FormCalc) –

var I=form1.ExpenseReport.Expenses.resolveNodes("Airfare[*]").length

if (I <= 1) then

Amount.rawValue = "0"


endif

 

Click event (JavaScript):

  1. this.resolveNode('Expenses._Airfare').removeInstance(this.parent.index);

if (xfa.host.version < 😎 {

xfa.form.recalculate(1);

}

 

 

Mouse Up (FormCalc):

var I=form1.ExpenseReport.Expenses.resolveNodes("Airfare[*]").length

if (I <= 1) then

    Summary._AirSumm.removeInstance(0)

    

endif

Answers (0)