Expand my Community achievements bar.

Autonumber each instance

Avatar

Former Community Member
Hello



I am using a variation of the Purchase Order for tracking bugs. Each time I add a new bug (via the instance manager) I want it to autonumber. Bug 1 would always be first. Add an instance would create a new row numbered 2.



Any ideas?
6 Replies

Avatar

Level 6
Put a read-only numeric field in your repeating subform. On initialize of the field, put this JavaScript:



this.access = "protected";

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



Jared

http://www.jlangdon.ca

Avatar

Former Community Member
That worked - thank you!



My script ended up:



this.access = "protected";

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



//I am buried in 2 subforms

Avatar

Former Community Member
New question - how to readjust numbers when they are removed? Right now if they are numbered 1-4 and I remove 3 it becomes 1,2,4.



Thanks again whomever can help!

Avatar

Former Community Member
I have successfully used:

this.rawValue = parent.index +1;

in the calculate event (of the first instance)

to show the numbering,

and used:

xfa.form.recalculate(true);

in the click event following the removeInstance AND addInstance code

to readjust the numbering once a row or subform is added or removed.



Hope that helps :-)

Avatar

Former Community Member
OUTSTANDING!

Worked like a charm!

I had to add a couple of more parents (nested) and then it worked.



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



Thank you very much.

Avatar

Level 2

Along this same line,

this.rawValue

= this.parent.index +1;

This works when adding row number, but I want the user to be able to enter a row  number and start a new sequential order.  Example:  user clicks "add row" button - the number 2 appears in second row,  user enters 14 in  next row number and clicks "add row". 15 should appear in the row number field.  Can this be accomplished?  If so, how?

I don't want the number to reset each time the form is opened.