Repopulate PDF Form Fields Down to New Section of Form with Button

New Here ,
Jan 09, 2019

Copy link to clipboard

Copied

At work, for each project I submit, I use a pdf form that has the information from the previous two editions of that project, as well as the current. We manually copy each field down each year (CurrentPages gets copied to PrevPages, etc.). I was hoping I could use javascript and a button to make this automatic. Can anybody help? Some of these fields are text fields, some are drop down lists, etc. Each field that needs populated will already need filled and will need cleared and/or overridden.

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

Yes, copying data between field is quite simple, and the type of field doesn't matter.

For your issue, the important thing is that the field names have a predicable and sequential naming convention. Then you can write code that takes advantage of the naming to find and transfer the field data

For example, you could name the fields in the first groupt "1.Text1" "1.Text2" etc. and the fields in the second group "2.Text1" "2.text2" and so on with as many groups as necessary.

This groups the fields using a number. Fields in each group have the same name, but with a different group prefix.

This code will transfer the data no matter the field type of number of fields in each group

for(var i=2;i>1;i--)

{

    aFldList = this.getField(i).getArray();

    for(var n=0;n<aFldList.length;n++)

      aFldList.value =  this.getField(aFldList.name.replace(/^\d/,i-1)).value;

}

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

80

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

Repopulate PDF Form Fields Down to New Section of Form with Button

New Here ,
Jan 09, 2019

Copy link to clipboard

Copied

At work, for each project I submit, I use a pdf form that has the information from the previous two editions of that project, as well as the current. We manually copy each field down each year (CurrentPages gets copied to PrevPages, etc.). I was hoping I could use javascript and a button to make this automatic. Can anybody help? Some of these fields are text fields, some are drop down lists, etc. Each field that needs populated will already need filled and will need cleared and/or overridden.

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

Yes, copying data between field is quite simple, and the type of field doesn't matter.

For your issue, the important thing is that the field names have a predicable and sequential naming convention. Then you can write code that takes advantage of the naming to find and transfer the field data

For example, you could name the fields in the first groupt "1.Text1" "1.Text2" etc. and the fields in the second group "2.Text1" "2.text2" and so on with as many groups as necessary.

This groups the fields using a number. Fields in each group have the same name, but with a different group prefix.

This code will transfer the data no matter the field type of number of fields in each group

for(var i=2;i>1;i--)

{

    aFldList = this.getField(i).getArray();

    for(var n=0;n<aFldList.length;n++)

      aFldList.value =  this.getField(aFldList.name.replace(/^\d/,i-1)).value;

}

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

81

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
Jan 09, 2019 0
Adobe Community Professional ,
Jan 09, 2019

Copy link to clipboard

Copied

Yes, copying data between field is quite simple, and the type of field doesn't matter.

For your issue, the important thing is that the field names have a predicable and sequential naming convention. Then you can write code that takes advantage of the naming to find and transfer the field data

For example, you could name the fields in the first groupt "1.Text1" "1.Text2" etc. and the fields in the second group "2.Text1" "2.text2" and so on with as many groups as necessary.

This groups the fields using a number. Fields in each group have the same name, but with a different group prefix.

This code will transfer the data no matter the field type of number of fields in each group

for(var i=2;i>1;i--)

{

    aFldList = this.getField(i).getArray();

    for(var n=0;n<aFldList.length;n++)

      aFldList.value =  this.getField(aFldList.name.replace(/^\d/,i-1)).value;

}

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...
Jan 09, 2019 1