Add Field and Immediate Add Text

Community Beginner ,
Sep 18, 2017

Copy link to clipboard

Copied

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

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.

TOPICS
Acrobat SDK and JavaScript

Views

247

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

Add Field and Immediate Add Text

Community Beginner ,
Sep 18, 2017

Copy link to clipboard

Copied

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

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.

TOPICS
Acrobat SDK and JavaScript

Views

248

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
Sep 18, 2017 0
Most Valuable Participant ,
Sep 18, 2017

Copy link to clipboard

Copied

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>

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...
Sep 18, 2017 0
Adobe Community Professional ,
Sep 18, 2017

Copy link to clipboard

Copied

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.

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...
Sep 18, 2017 0
Community Beginner ,
Sep 19, 2017

Copy link to clipboard

Copied

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.

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...
Sep 19, 2017 0
Most Valuable Participant ,
Sep 19, 2017

Copy link to clipboard

Copied

Weird... Can you share the file?

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

Copy link to clipboard

Copied

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.

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