These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

LC Dynamic Form Need Script to auto increment cell by A, B, C....AA, BB, rather than numeric. Is this possible

jasaussie
Registered: Feb 8 2011
Posts: 8
Answered

I have a dynamic LC form that has a table that auto increments a cell in each row by 1, 2, 3... when a row is added or deleted. My client want to use A, B, C...AA, BB, CC... instead of numeric numbers. This is the script I use to auto increment by number:
 
this.access = "protected";
this.rawValue = this.parent.index +1;
   
Is this possible?
 
jasaussie

jasaussie

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Certainly it's possible, character codes are sequential. Here's some code that increments A-Z.


// Initialize
var cInc = "A";

// Increment
var nInc = cInc.charCodeAt(0);
if(cInc < "Z")
cInc = String.fromCharCode(++nInc);


To add more characters "AA" "BB" etc. requires code for getting the current length and rebuilding the string.



Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

jasaussie
Registered: Feb 8 2011
Posts: 8
I'm a novice to scripting and trying to add script to my file. Do this code all go in the EventCalculate? When I use the code all cells in my column have a "B".

jasaussie

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
I did not write a complete script. This code was just to show how a text value can be incremented. You could in fact use the row index as the basis for the text value. In this case the code would be placed in the "initialize" event.

var nBaseVal = ("A").charCodeAt(0);
this.rawValue = String.formCharCode(nBaseVal + this.parent.index);

Again, this is not complete. To handle more than 26 rows the script will need to add extra characters. The is also the issue of deleting and inserting rows. The initialize script may need to be rerun in these situations.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script