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

Field value edits within a loop

Community Beginner ,
Oct 27, 2018 Oct 27, 2018

Copy link to clipboard

Copied

I have a loop to iterate through all of the fields and copy them from a target pdf to the current pdf.

This currently works well with manually calling the fields, and with console.log within the loop. But as soon as the field.value is updated with the field.value of the other pdf the software crashes (infinite loop?). It even crashes if the field.value is manually set for all fields. I must be missing something simple..

Here is my code:

thisDoc = this;

var docName = app.browseForDoc();

app.openDoc(docName.cPath);

var d = app.activeDocs;

var thatDoc = d[d.length-1];

var i = 0;

while (i<thatDoc.numFields){

var oldName = thatDoc.getNthFieldName(i);

var old = thatDoc.getField(oldName);

if(old.type == "text"){

   if (thisDoc.getField(oldName) != null){

   var cur = thisDoc.getField(oldName)

cur.value = old.valueAsString;

   }

} i++;

}

thatDoc.closeDoc();

Any help would be appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

501

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
community guidelines

correct answers 1 Correct answer

Community Beginner , Nov 09, 2018 Nov 09, 2018

Found the answer - the javascript api for adobe is single threaded, and as such a loop that relies on the commit chain (on a button/field object) will always fall outside of that commit chain if it's too long (I think!).

Creating this at a document level, after stuffing some lists, seemed to work perfectly well.

Votes

Translate

Translate
LEGEND ,
Oct 28, 2018 Oct 28, 2018

Copy link to clipboard

Copied

Try simplifying that first block of code to:

thisDoc = this;

var docName = app.browseForDoc();

var thatDoc = app.openDoc(docName.cPath);

var i = 0;

Votes

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
community guidelines
Community Beginner ,
Oct 28, 2018 Oct 28, 2018

Copy link to clipboard

Copied

This is something I tried a little while ago, and it just doesn't access the other file 'thatDoc' after opening.

It's also not why this loop isn't working - as the code works great when printing instead of changing values.

I appreciate the idea though - and it's also something I can do within the loop - but I'm keeping it obtuse to try and see what does and doesn't work. Thanks!

Votes

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
community guidelines
Community Beginner ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

LATEST

Found the answer - the javascript api for adobe is single threaded, and as such a loop that relies on the commit chain (on a button/field object) will always fall outside of that commit chain if it's too long (I think!).

Creating this at a document level, after stuffing some lists, seemed to work perfectly well.

Votes

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
community guidelines