Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add Field and Immediate Add Text

Community Beginner ,
Sep 18, 2017 Sep 18, 2017

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");

TOPICS
Acrobat SDK and JavaScript
751
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Sep 26, 2017 Sep 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.

...
Translate
Community Expert ,
Sep 18, 2017 Sep 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2017 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 19, 2017 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2017 Sep 19, 2017

Weird... Can you share the file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 26, 2017 Sep 26, 2017
LATEST

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.

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