Concatenate a string in to the this getField() property.

Participant ,
Oct 23, 2017

Copy link to clipboard

Copied

Hi guys. Wondering if it's possible to concatenate a string in to the this getField() property.

I'll elaborate.

I have a script writing pro forma with two main text fields SCRIPT-1 and SCRIPT-2. (The same page is saved as a template.)

With a button I can spawn a new page with new text fields then the fields names become P1.ScriptPage.SCRIPT-1 and P1.scriptfile.SCRIPT-2.

Each page increments the 'P' value by one for the UID.

What I want to do is run a simple for loop to run through all the iterations of SCRIPT-1 and 2 on each page and bring them in to a single variable for outputting in a single textbox 'all2oneText'. This all2oneText is on a third spawned page of a different template.

This is the code I am using. Can someone help me to correct it?

getField("all2oneText").value = this.getField("SCRIPT-1").valueAsString + "\n";

getField("all2oneText").value += this.getField("SCRIPT-2").valueAsString + "\n";

//gets SCRIPT-1 and SCRIPT-2 in to all2oneText

if(numPages > 2){

getField("all2oneText").value += "More than 2 pages \n";

//checks that page quantity is big enough to contain some iterations of script-1 / script-2 items.

//Also I am outputting "More than 2 pages" to show myself that the code is actually firing.

//my simple for Loop . This is where the code doesn't work. I must have it completely wrong.

for(i = 1; i < numPages-1; i++) {

container = {};

//blank variable called container.

getField("all2oneText").value += this.getField(container["P" + i + ".ScriptPage.SCRIPT-1"]).valueAsString + "\n" + this.getField(container["P" + i + ".ScriptPage.SCRIPT-2"]).valueAsString + "\n";

//combining P with i to create the P number + "ScriptPage.SCRIPT-1" should equate to P1.ScriptPage.SCRIPT-1 output to the field.

}

}

I have completely gotten that wrong at the end I'm certain because I have no idea how to concatenate a string as a variable.

I wonder if its because the " " quotation marks are not part of the concatenation

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

You don't need the variable container.

You can access the field like this:

this.getField("P" + i + ".ScriptPage.SCRIPT-1").valueAsString

TOPICS
Acrobat SDK and JavaScript

Views

504

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Concatenate a string in to the this getField() property.

Participant ,
Oct 23, 2017

Copy link to clipboard

Copied

Hi guys. Wondering if it's possible to concatenate a string in to the this getField() property.

I'll elaborate.

I have a script writing pro forma with two main text fields SCRIPT-1 and SCRIPT-2. (The same page is saved as a template.)

With a button I can spawn a new page with new text fields then the fields names become P1.ScriptPage.SCRIPT-1 and P1.scriptfile.SCRIPT-2.

Each page increments the 'P' value by one for the UID.

What I want to do is run a simple for loop to run through all the iterations of SCRIPT-1 and 2 on each page and bring them in to a single variable for outputting in a single textbox 'all2oneText'. This all2oneText is on a third spawned page of a different template.

This is the code I am using. Can someone help me to correct it?

getField("all2oneText").value = this.getField("SCRIPT-1").valueAsString + "\n";

getField("all2oneText").value += this.getField("SCRIPT-2").valueAsString + "\n";

//gets SCRIPT-1 and SCRIPT-2 in to all2oneText

if(numPages > 2){

getField("all2oneText").value += "More than 2 pages \n";

//checks that page quantity is big enough to contain some iterations of script-1 / script-2 items.

//Also I am outputting "More than 2 pages" to show myself that the code is actually firing.

//my simple for Loop . This is where the code doesn't work. I must have it completely wrong.

for(i = 1; i < numPages-1; i++) {

container = {};

//blank variable called container.

getField("all2oneText").value += this.getField(container["P" + i + ".ScriptPage.SCRIPT-1"]).valueAsString + "\n" + this.getField(container["P" + i + ".ScriptPage.SCRIPT-2"]).valueAsString + "\n";

//combining P with i to create the P number + "ScriptPage.SCRIPT-1" should equate to P1.ScriptPage.SCRIPT-1 output to the field.

}

}

I have completely gotten that wrong at the end I'm certain because I have no idea how to concatenate a string as a variable.

I wonder if its because the " " quotation marks are not part of the concatenation

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

You don't need the variable container.

You can access the field like this:

this.getField("P" + i + ".ScriptPage.SCRIPT-1").valueAsString

TOPICS
Acrobat SDK and JavaScript

Views

505

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 23, 2017 0
Adobe Community Professional ,
Oct 23, 2017

Copy link to clipboard

Copied

You don't need the variable container.

You can access the field like this:

this.getField("P" + i + ".ScriptPage.SCRIPT-1").valueAsString

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 23, 2017 0
Participant ,
Oct 23, 2017

Copy link to clipboard

Copied

that was what I was after. thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 23, 2017 0