Totals Based on Multiple Criteria in Repeating Rows

Avatar

Avatar

meem23

Avatar

meem23

meem23

09-12-2014

Hi All,

I have 3 dropdowns (DD1, DD2, DD3) and one textfield (TF1) in repeating rows (not in a table).  Each dropdown has two choices and the textfield is free-form. Outside of the rows (in a different subform) I want totals based on multiple criteria from the dropdowns and textfields.

The following script works great to get a total number of one choice from one dropdown.

this.rawValue = xfa.resolveNodes('form1.Form.row[*].DD1.[$.rawValue == "2"]').length;

Problem is how do I calculate the totals for the following based on the criteria listed in each row.

Find the totals for ML

Number of New Forms 1-2 Pages: (result should be 2)

Number of New Forms 3+ Pages: (result should be 1)

Number of Revised Form: (result should be 0)

In row #1:  select “New” as a choice from DD1, “Form” as choice from DD2, “ML” as a choice from DD3 and enter “5” in TF1.

In row #2:  select “New” as a choice from DD1, “Form” as choice from DD2 , “ML” as a choice from DD3 and enter “1” in TF1.

In row #3:  select “New” as a choice from DD1, “Form” as choice from DD2, “ML” as a choice from DD3 and enter “2” in TF1.

In row #4:  select “Revised” as a choice from DD1, “Series” as choice from DD2, “ML” as a choice from DD3 and enter “1” in TF1.

In row #5:  select “New” as a choice from DD1, “Form” as choice from DD2, “PM” as a choice from DD3 and enter “1” in TF1.

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372
_Bruce_Robertson
MVP

13-12-2014

Try something like;


var mlNewForms1or2Pages = 0;
var mlNewFormsOver3Pages = 0;
var mlRevisedForms = 0;
var rows = xfa.resolveNodes('form1.Form.row[*]');
for (var i = 0, limit = rows.length; i < limit; i++)
{
var currentRow = rows.item(i);
if (currentRow.DD1.rawValue == "1") // new
{
  if (currentRow.DD2.rawValue == "1") // form
  {
   if (currentRow.DD3.rawValue == "1") // ML
   {
    if (parseInt(currentRow.TF1.rawValue, 10) > 2)
    {
     mlNewFormsOver3Pages++;
    }
    else
    {
     mlNewForms1or2Pages++;
    }
   }
  }
}
else // revised
{
  if (currentRow.DD2.rawValue == "1") // form
  {
   if (currentRow.DD3.rawValue == "1") // ML
   {
    mlRevisedForms++
   }
  }
}
}
console.println(mlNewForms1or2Pages);
console.println(mlNewFormsOver3Pages);
console.println(mlRevisedForms);




To do the same using predicates you could do;


var mlNewForms1or2Pages = 0;


var mlNewFormsOver3Pages = 0;


var mlRevisedForms = 0;


 


mlNewForms1or2Pages = xfa.resolveNodes('form1.Form.row.[DD1 == 1 and DD2 == 1 and DD3 == 1 and TF1 <= 2]').length;


mlNewFormsOver3Pages = xfa.resolveNodes('form1.Form.row.[DD1 == 1 and DD2 == 1 and DD3 == 1 and TF1 > 2]').length;


mlRevisedForms = xfa.resolveNodes('form1.Form.row.[DD1 == 2 and DD2 == 1 and DD3 == 1]').length;


 


But if you wanted totals for all the permutations then this could become slow.

Regards

Bruce