Calculating subtotals/page totals | Community
Skip to main content
New Participant
November 9, 2018
Solved

Calculating subtotals/page totals

  • November 9, 2018
  • 15 replies
  • 17786 views

Hello;

I'm trying to calculate row subtotals and a page total within a repeating table (see below).

What code should I be using for the Total Value column to total each row and then the Page Total row at the bottom to add up all of the rows in the Total Value column? I know the easiest way is with FormCalc but everything I've tried has duplicated the values from the previous row to the new row when the Add '+' button is clicked.

I appreciate your help.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by radzmar

Well, the total value per row should be calculated with:

$ = Quantity * Value

And the page total with:

$ = Sum(Row1[*].TotalValue)

Both scripts are in FormCalc not JavaScript!

15 replies

New Participant
November 13, 2018

I moved your question to the LiveCycle Designer forum.

New Participant
November 13, 2018

subieguy2​ thanks for the suggestion. I see this is in AcroForm but it shouldn't be all that hard for me to translate to LiveCycle JavaScript (I've done it before with other code). I appreciate it. I figure it's something that I'm missing that's not clearing the row subtotal when a new row is created. Everything else seems to be working fine, so maybe this will help. I'll keep you posted. Thanks

New Participant
November 13, 2018

try67​ Yes, it is a LiveCycle form. Sorry, I should have put that in the description. It has the ability to add repeating rows to the table in the screenshot (see the plus/minus buttons to the right of each row).

subieguy2
New Participant
November 12, 2018

Something like this might work for you...

var qtyOne = this.getField("Quantity Field Row 1 Name").value;

var qtyTwo = this.getField("Quantity Field Row 2 Name").value;

var qtyThree = this.getField("Quantity Field Row 3 Name").value;

var valOne = this.getField("Value Field Row 1 Name").value;

var valTwo = this.getField("Value Field Row 2 Name").value;

var valThree = this.getField("Value Field Row 3 Name").value;

var totalOne = this.getField("Total Field Row 1 Name").value;

var totalTwo = this.getField("Total Field Row 2 Name").value;

var totalThree = this.getField("Total Field Row 3 Name").value;

if (qtyOne != ""){

totalOne = (qtyOne * valOne);

event.value = totalOne;

}

if (qtyTwo != ""){

totalTwo = (qtyTwo * valTwo);

event.value = totalTwo;

}

if (qtyThree != ""){

totalThree = (qtyThree * valThree);

event.value = totalThree;

}

New Participant
November 9, 2018

Is this an LCD form?