Expand my Community achievements bar.

SOLVED

Auto Numbering

Avatar

Level 2

I have created a dynamic form in LiveCycle ES Designer. It has a dynamic table and a dynamic text field. The table has a single row with 6 cells. Inside of each cell I have created sub forms and then placed various boxes (text, drop downs, etc). I have created an add and remove button to replicate the table if another one is needed.

In my table in the first cell I have a drop down field currently that goes from 1 to 75. When you click on the add row button and it replicates another row I would like for it to auto populate the field to indicate #2, #3, so on and so on as you add table rows. I realize that it can not be a drop down field and will most probably have to be a text or number field.

What I do not know however is the java that will tell it to generate the next sequencial number when I add a new row.

Can anyone help or point me in the right direction to find my answer?

Thanks,

Shane

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

Place this on the calculate event of a number field of the repeating row:

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

Then, if you need to display # in front of the number, you can place the following in "Patterns..." found on the "Field" tab of the "Object" pallet for the field with the script:

     num{('#'zzzz9)}

Good luck!

Stephen

View solution in original post

6 Replies

Avatar

Correct answer by
Level 7

Hi,

Place this on the calculate event of a number field of the repeating row:

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

Then, if you need to display # in front of the number, you can place the following in "Patterns..." found on the "Field" tab of the "Object" pallet for the field with the script:

     num{('#'zzzz9)}

Good luck!

Stephen

Avatar

Level 2

The above worked great and is I believe half of my solution. When I added the script to my numeric field and then tried to preview the form it would give me an error. I believed it was due to the fact that I have a single talble and in each cell I have created a positioned subform and placed two fields in each cell. I did this because I could not find a way to replicate a two row table at the same time. When I tried it would repeat each row but not keep them positioned (row 1 on top of row 2). When I would repeat the row it would put row 1 on top of the new row 1 and the same with row 2. I need the rows to repeat in the exact position as the original. The only solution I found at the time was the subform in a single cell with both my fields in that sub form.

I went to an earlier template that I had of the current form I use that only had the single cell with no subform and put in the script you provided and it worked perfectly when I would add a row in regards to the numbering.

My new question is do you know what I would need to do to create a table with multiple rows (currently I would need 2 rows) and get the to repeat so I would not need to use the subform method I used. Then I could input the script you provided to me and I believe it would work perfectly.

Thanks,

Shane

Avatar

Level 5

Thanks for this script.  I was wondering if it's possible to make the numbering dynamic, so that if you add several rows but then decide to delete a few in the middle, to make the row numbers readjust to the proper sequence.

Avatar

Level 5

I'm not an experienced programmer/scripter, so I was able to piece this together, but there must be some cleaner way to do this with an automatic counter of some sort:


var vIndex = ["1", "2",  "3", "4", "5", "6", "7", "8", "9",]


var i = this.parent.index;


this.rawValue = vIndex[i];


Avatar

Level 10

Hi,

If your code is in the calculate event, use Stephen's code above, but add the following line before it.

var rowCount = this.parent.instanceManager.count;

This looks a little strange as we don't need to do anything with rowCount but just referencing it will cause the calculate event to fire whenever the instanceManager.count value (the number of rows) changes and so the row number will be recalculated on a delete.

Your calculate event code should end up looking like;

var rowCount = this.parent.instanceManager.count;

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

There are some other examples in this blog post http://adobelivecycledesignercookbookbybr001.blogspot.com.au/2013/05/numbering-rows-in-livecycle-des...

Regards

Bruce

Avatar

Level 5

Perfect, works great!  Just does what I needed.  I'm reposting your script here for future readers, for easier reading:

Really appreciate the help,

Kam.


var rowCount = this.parent.instanceManager.count;


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