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

Spawn page from template with partially resetted fields

Community Beginner ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Background: I have a PDF for reporting purposes where the second page repeats as many times as needed.

The number of repetition however is always different depending on the case.

I was successful in spawning a page from a template through a button with this code

var a = this.getTemplate ("template");

a.spawn();

However when I press the button the previously filed out page is basically being duplicated and fields are already filled out.

How can I reset all fields except for one certain field when clicking the spawn button?

Don't know if this should be another topic:

How can I make a sum of a certain field that repeats on every spawned page?

I know that the spawned field names are:

Pnn.template.fieldname

How can I make a sum of a fieldname that appears on every spawned page but with a unique Pnn Prefix?

Thanks a lot in advance for anyone taking the time to answer this.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.2K

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 Expert , Mar 07, 2018 Mar 07, 2018

With your script, the fields should not be filled in. You are using the default parameters to Template.spawn(), which means that bRename is set to "true" - which means that all fields will be renamed (see here for more information about the parameters: Acrobat DC SDK Documentation ).

Is it possible that the fields you are filling out are on a template page that is not hidden when you load the document? In this case, you are actually modifying the template page before it gets spawned, so you end u

...

Votes

Translate

Translate
Community Expert ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

With your script, the fields should not be filled in. You are using the default parameters to Template.spawn(), which means that bRename is set to "true" - which means that all fields will be renamed (see here for more information about the parameters: Acrobat DC SDK Documentation ).

Is it possible that the fields you are filling out are on a template page that is not hidden when you load the document? In this case, you are actually modifying the template page before it gets spawned, so you end up with a copy of the state of the page at the time you spawn a new instance of that page. The solution to this is to hide your page template and use a script to spawn the first instance of the page as well. This way, you will always start out with a blank page.

As to your second question: Your summary field needs to find out it's own name, and then based on that name determine in what group it is in (e.g. the Pnn.template part of the name). You then use that part to create your field names for the fields you want to sum up.

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 ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Oh damn, that was it! Thanks a lot for your answer!

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 ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Now I am running into another error which makes sense:

I have calculations on the template page field3 = field1+field2 as the prefixes and suffixes of the fieldnames are changing the calculations are broken.

How can I fetch the current page I am on from the Pnn.fieldname.template of the spawned page field structure so that the calculation does not get lost when spawning a new page? thx a lot in advance!

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 Expert ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

LATEST

Use something like this as your calculation script:

// get this fields name

var fieldName = event.target.name;

// strip off the last part of the name

var groupName = fieldName.substring(0, fieldName.lastIndexOf(".")+1);

// calculate the sum

event.value = this.getField(groupName + "Field1").value + this.getField(groupName + "Field2").value;

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