Copy link to clipboard
Copied
I have a table with 50 fillable rows; the first column indicates a line number. The field name is txtLnNo1 for the first, txtLnNo2 for the second, and so forth. I would like for it to auto-generate the line number in each field, and when an additional page is generated, have it start with the last number of the previous page plus 1 (i.e., for page 2, 51; for page 3, 101; etc.) I did this before in Adobe LiveCycle Designer at a previous job using a script like "this.rawValue = this.parent.index +1;" but with this job, I am using InDesign exported to Acrobat. I have attached the PDF for reference. Thank you for being so helpful.
Copy link to clipboard
Copied
Copy-paste this script in the JS Console, select all and hit ENTER.
This script uses the field name number as the field value.
It works regardless of the number of fields and the number of pages.
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/txtLnNo/.test(oFld.name))) {
var sNom = oFld.name.split("o");
var sSuffix = sNom.pop();
oFld.value = sSuffix;
}
}
Copy link to clipboard
Copied
Depending on what you want to do this script might be even better as it also assigns the value as the "default value" (orange line added).
This allows a Reset/clear without deleting the fields value.
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/txtLnNo/.test(oFld.name))) {
var sNom = oFld.name.split("o");
var sSuffix = sNom.pop();
oFld.value = sSuffix;
oFld.defaultValue = sSuffix;
}
}
Copy link to clipboard
Copied
Copy-paste this script in the JS Console, select all and hit ENTER.
This script uses the field name number as the field value.
It works regardless of the number of fields and the number of pages.
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/txtLnNo/.test(oFld.name))) {
var sNom = oFld.name.split("o");
var sSuffix = sNom.pop();
oFld.value = sSuffix;
}
}
Copy link to clipboard
Copied
Depending on what you want to do this script might be even better as it also assigns the value as the "default value" (orange line added).
This allows a Reset/clear without deleting the fields value.
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/txtLnNo/.test(oFld.name))) {
var sNom = oFld.name.split("o");
var sSuffix = sNom.pop();
oFld.value = sSuffix;
oFld.defaultValue = sSuffix;
}
}
Copy link to clipboard
Copied
Thank you so much, JR! This works great! When I later find the "add page" script I have saved and implement it, I will see how it will work with that.
Copy link to clipboard
Copied
I have one more question about this script. When I use a script to spawn another page from the first, will the numbering continue from the last number on the previous page or restart at 1? Thank you again for your help!
Copy link to clipboard
Copied
The script uses the number at the end of the field name (after the "o") to assign its value.
So the numbering will start at 1 on each new page.
Copy link to clipboard
Copied
Thank you, JR. I saw that when you first presented the code, but it slipped my mind when I posted. My next step would be to find and tweak the script that spawns a new page to add 50 to the numbers at the end of the field names for the second page, 100 to the third page, and so on.
Copy link to clipboard
Copied
Will this template be hidden?
Is this the only page in the document or are there other different pages that can be interspersed?
Copy link to clipboard
Copied
There will be other pages interspersed in the document. This particular page will be showing initially, and if more are needed for input, the user will press an "Add Page" button to generate additional pages. I currently have a simple script to generate one page at a time, but later, I look to add a prompt to input the number of pages to create multiples. This page is one of two tables that will need additional pages generated. This form was initially built in Excel, and the two tables have up to 500 rows for input. I am using InDesign to recreate them as fillable PDFs.
Copy link to clipboard
Copied
Assuming this is the only page that can be spawned in the document this script will work.
It use the "spawned page number" instead of the page number (spawned fields are renamed like this: P1.templatexxxx.fieldName ) so it's independent of any interleaved pages.
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/txtLnNo/.test(oFld.name))) {
if (oFld.page == 0) { // first page
var sNom = oFld.name.split("o");
var sSuffix = sNom.pop();
oFld.value = sSuffix;
oFld.defaultValue = sSuffix;
}
else { // spawned pages
var sNom = oFld.name.split("o");
var sSuffix = sNom.pop();
var sNom = oFld.name.split(".");
var sPrefix = sNom.shift();
var sPrefix = sPrefix.replace(/P/, "");
var n2Add = (50 * (Number(sPrefix)));
oFld.value = Number(n2Add) + Number(sSuffix);
oFld.defaultValue = Number(n2Add) + Number(sSuffix);
}
}
}
Copy link to clipboard
Copied
Thank you, JR! There are two other pages to be spawned in the document, so will I be able to use the code on all three of them? They will all have the line number column (txtLnNo) to help the user distinguish the number of items and provide a sense of order within each table. Other than those three, all other pages in the document will not be spawned. There are nine pages, and I have six of them developed so far. As I mentioned in a prior reply, this form document was originally built in Excel, where those three pages have 500 rows to have the capacity for large orders. There are nine pages, and I have six of them developed so far.
Copy link to clipboard
Copied
" will I be able to use the code on all three of them?"
You must run this script one time to fill the existing page, and you must run it each time a new page is spawned.
This will overwrite the already filled fields but it doesn't matter since it doesn't change their number.
Copy link to clipboard
Copied
How do I incriment a field (Count) in a repeatable subform with letter as I add new instances of that subform. The field I am updating is the first filed in a line of fields.
Eg.
A.
B.
C.
D.
The Sub Form is (topmostSubform.Page_1.Para3.Interviewed_Personnel_subform) and the Field I want to update is
topmostSubform.Page_1.Para3.Interviewed_Personnel_subform.Count. I use the "+" to create a new instance of (Interviewed_Personnel_subform) and that is when I want the new instance of (Count) with the next letter.