Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

How do I get an incremental counter on the added subforms after pressing the "Add" button


Level 1

I have a numeric field set up with default set to 1, when I press the  "Add" button a new version of the subform is added after.  My numbering is all messed up.  If I press the add button, the first subform becomes 2 and the added one stays 1.  When I press the add button on the second version of the subform, subform 1 becomes "3", subform 2 becomes "2" subform 1 becomes "1".  But if I press the add button on subform 1 again, subform 1 stays "2", subform 2 says "2" and subform 3 says "1"

My "Add" button coding is


Subform.NumericField.rawValue =

parseInt(Subform.NumericField.rawValue) + 1;

My delete button coding is


It's set like this to always remove the "last" subform, but might be worthwhile to be set up to remove "that" instance of the subform but I don't know how to do that.  Can anyone help?

2 Replies


Level 10

Hi there,

if you want to have the exact number of row your numeric field represents, you should use the calculate event instead of adding 1 each time you click add button. So in the calculate event of your numeric field, simply input the index value of the subform + 1...

You can also use the index to remove the instance of the subform of the delete button that have been clicked.

Ensure that specifying parent refers to the right parent as the subform in question.

Parent property only works if the buttons are inside the subform.


Level 1

I've tried numerous scripts in the calculate event, nothing works there.

I don't understand what is meant by parent here either, I tried to put that coding into my delete buttons and it just deletes the first record, not the one it's on.

Sent from my iPhone