Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Totals Based on Multiple Criteria in Repeating Rows

Avatar

Avatar
Validate 1
Level 2
meem23
Level 2

Like

1 like

Total Posts

94 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
meem23
Level 2

Like

1 like

Total Posts

94 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
meem23
Level 2

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
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_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