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.
SOLVED

Using .index+1 in Master Pages

Avatar

Level 6

Typically I would use a textfield with the script "this.rawValue = SubformA.index + 1;" to track/count the number of instances of SubformA.  So,if I have an Add button and a new verison of the subform is created, the textfield would read 2,3,4 etc.

Simple, but I need to place the script (this.rawValue = SubformA.index + 1;) in a Master page so i can use it in a header on every page.  To do this, I used the full path to reference the Subform (this.rawValue = xfa.form.form1.SubfromA.index+1;) however every time a new version of the subform is created (by pressing the add button), it keeps the instance at 1. It no longer increases by 1 as it did when the script wasn't in the Master Page.

Any idea what's going on? How can I use .index+1 in the Master page and still have it increase by one easch time a Subfom (not in the Master page) is created?

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I would recommend using .count instead of index.

this.rawValue = page1._SubformA.count;

The underscore in front of the SubformA is shorthand for instanceManager.

If the form is likely to extend beyond one page, you should set the binding of the textfield to global in the Object > Binding palette.

Good luck,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

I would recommend using .count instead of index.

this.rawValue = page1._SubformA.count;

The underscore in front of the SubformA is shorthand for instanceManager.

If the form is likely to extend beyond one page, you should set the binding of the textfield to global in the Object > Binding palette.

Good luck,

Niall

Avatar

Level 6

Thanks Niall! I extended your recommendation and used:

this.rawValue = xfa.form.form1.RN._RnSet.count;

Works great!!!!

Avatar

Level 6

Sorry, I thought this was answered. The script works; however, it's not increasing the subform index by 1. I have an "add button" in the form, so each time it's pressed, I'd like the textfield to show the incremental index number.

Thanks

Avatar

Level 10

Hi,

The script in the calculate event of the textfield, will give you the total number of rows in the table (eg number of instances of the repeating object). This is on the basis that you have a single textfield, separate from the table.

If on the other hand you have the textfield in the table and you want to display the current index, then have a look at this solution: http://assure.ly/gBJYj9. Tables 4 and 5 are table objects, whereas Table 6 uses subforms. All of these have a textfield in the repeating object, which displays that row's index.

// calculate item number from index

this.rawValue = this.parent.index + 1;

Hope that helps,

Niall

Assure Dynamics