Skip to main content
Participant
September 18, 2017
Answered

Add Field and Immediate Add Text

  • September 18, 2017
  • 4 replies
  • 737 views

Hello,

I have a sequence of scripts I'm using to create copies of a page based on number of copies requested by the user (TotalPages). Subsequent to that I am running a script to rename all of the copied fields to a unique field by recreating the field name to stop sharing data entered into the field. Both of these scripts run fine for their intended purpose. However, I would like to at the same time as renaming the field to enter the page value before moving to the next field. I am new to JavaScript so I'm hoping someone can tell me what I'm doing wrong.

This works for me:

var TotalCopies = this.getField("TotalPages").value

for (var i=0;i<TotalCopies;i++)

{

try{

var rct=this.getField("CurrentPage."+i).rect;

var pg=this.getField("CurrentPage."+i).page;

this.addField("CurrentPg."+i,"text",pg,rct);

}catch(e){break}

}

this.removeField("CurrentPage");

When I tried to add entry of text (line 08) into the newly created field I couldn't get it to work. What I tried below:

var TotalCopies = this.getField("TotalPages").value

for (var i=0;i<TotalCopies;i++)

{

try{

var rct=this.getField("CurrentPage."+i).rect;

var pg=this.getField("CurrentPage."+i).page;

this.addField("CurrentPg."+i,"text",pg,rct);

this.getField("CurrentPg."+i).value = pg+1;

}catch(e){break}

}

this.removeField("CurrentPage");

This topic has been closed for replies.
Correct answer thesonofdarwin

I was able to resolve this issue by creating another variable and using that to add the value to the field. Below works with no problems.

var TotalCopies = this.getField("TotalPages").value

for (var i=0;i<TotalCopies;i++)

{

try{

var rct=this.getField("CurrentPage."+i).rect;

var pg=this.getField("CurrentPage."+i).page;

var ts=this.getField("CurrentPage."+i).textSize;

var tf=this.getField("CurrentPage."+i).textFont;

var f=this.addField("CurrentPg."+i,"text",pg,rct);

f.textSize=ts;

f.textFont=tf;

var pg1=this.getField("CurrentPg."+i).page;

this.getField("CurrentPg."+i).value = pg1+1;

}catch(e){break}

}

this.removeField("CurrentPage");

Specifically lines 12 and 13 resolved the problem.

4 replies

thesonofdarwinAuthorCorrect answer
Participant
September 26, 2017

I was able to resolve this issue by creating another variable and using that to add the value to the field. Below works with no problems.

var TotalCopies = this.getField("TotalPages").value

for (var i=0;i<TotalCopies;i++)

{

try{

var rct=this.getField("CurrentPage."+i).rect;

var pg=this.getField("CurrentPage."+i).page;

var ts=this.getField("CurrentPage."+i).textSize;

var tf=this.getField("CurrentPage."+i).textFont;

var f=this.addField("CurrentPg."+i,"text",pg,rct);

f.textSize=ts;

f.textFont=tf;

var pg1=this.getField("CurrentPg."+i).page;

this.getField("CurrentPg."+i).value = pg1+1;

}catch(e){break}

}

this.removeField("CurrentPage");

Specifically lines 12 and 13 resolved the problem.

Participant
September 19, 2017

I removed the try/catch statements and no error message is generated due to the addition of line 08. The rest of the actions complete successfully but I cannot get the value of pg+1 to go into the newly created field. It seemingly just skips that step with no error.

try67
Community Expert
Community Expert
September 19, 2017

Weird... Can you share the file?

Inspiring
September 18, 2017

The try catch statements trap the error message and then it is up to the programmer to handle the error. Your code sends the error message to the bit bucket and it is lost. You can issue an alert and display the error object using JavaScript.

try67
Community Expert
Community Expert
September 18, 2017

Remove the try-catch clause and see if there are any error messages

generated by this line.

On Mon, Sep 18, 2017 at 11:15 PM, thesonofdarwin <forums_noreply@adobe.com>