Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Achieving Sum with Variable Rows

Avatar

Former Community Member

Greetings!

Here is a description of my situation:

  • In Field 1, the user enters an amount. Let's say $10.
  • In Field 2, the user enters a piece of metadata.  The user may then click a button to enter another piece of metadata (another Field 2 displays).  There is only one piece of metadata allowed per line, however there is no limit to how many pieces of metadata may be entered.  Basically, Field 2 is just a repeating subform with a text field in it.
  • Field 3 is a calculated field.  This is where I need to place some JavaScript or FormCalc.  What I need is the amount in Field 1 (in this example, $10) to be multiplied by the number of instances of Field 2, however many that may be. 

Any help would be appreciated.

Thank you.

4 Replies

Avatar

Level 10

All you need to do is get how many instances of Field2 there is... this.resolveNode("YourSubform").instanceManager.count... it's easier using rows for that

Avatar

Former Community Member

Thank you for that.  How do I make it so it counts only instances that actually contain metadata?  I need to make sure it doesn't count any Field 2 that is accidentially left blank.

Avatar

Level 10

Make a var that counts how many fields are not blank;

var intCountMetaData = 0;

for (var i = 0; i < this.resolveNode("YourSubform").instanceManager.count - 1; i++){

     if (this.resolveNode("YourSubForm[" + i.toString() + "].Field2").rawValue != null){

          intCountMetaData += 1;

     }

}

Avatar

Former Community Member

I couldn't get this to work.  I get a syntax error.  I'm using FormCalc on my calculate event for Field 3 though.