Skip to main content
Inspiring
October 23, 2017
Answered

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

  • October 23, 2017
  • 2 replies
  • 2680 views

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

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Bernd Alheit

You don't need the variable container.

You can access the field like this:

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

2 replies

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
October 23, 2017

You don't need the variable container.

You can access the field like this:

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

sillybombAuthor
Inspiring
October 23, 2017

that was what I was after. thanks