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

Calculations in template with renamed fields?

Community Beginner ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

I have a form with two templates that are spawned as necessary (user generated) the first is named "tpt_Soil" and the second is "tpt_Veg". The entire form (with no additional pages added) is 11 pages. Sometimes the user will need additional copies of "tpt_Soil", sometimes not. Same with "tpt_Veg". Copies of the second one could start on page 12, but it also could start on page 15 or 16, depending on the scenario.

 

"tpt_Soil" has no calculations, so my button action javascript works no problem:

 

var SoilPage = this.getTemplate("tpt_Soil");
SoilPage.spawn(this.numPages, true, false)

 

However, "tpt_Veg" is more complicated, it is two pages long AND has a number of calculated fields. How do I rewrite the scripts for those fields so that they will still work in the spawned (and renamed) templates?

 

So for example on tpt_Veg there are fields named: F1a.Strata.Canopy, F1a.Strata.SubCanopy, F1a.Strata.Shrub, F1a.Strata.Herb and then F1a.Strata_Total which is the sum of the F1a.Strata fields.

 

Right now that's done through the pick-list calculations, but obviously won't work when the fields are renamed Pxx.F1a.Strata because I don't know what page they will end up as.

TOPICS
JavaScript , PDF forms

Views

368

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 2 Correct answers

Community Expert , Apr 05, 2021 Apr 05, 2021

Names of fields in a spawned page are predictable. They are made out of the page number to which the page was spawned, the name of the template and the original name of the field. You can use this pattern to write a script that will perform these calculations, even when the fields are on spawned pages.

Votes

Translate

Translate
Community Expert , Apr 05, 2021 Apr 05, 2021

You don't need to, because it's the same page (presumably) as the one where the calculated field is on, so you can get that information from that field's name, which you can access using event.target.name .

Votes

Translate

Translate
Community Expert ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Names of fields in a spawned page are predictable. They are made out of the page number to which the page was spawned, the name of the template and the original name of the field. You can use this pattern to write a script that will perform these calculations, even when the fields are on spawned pages.

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

What if I don't know what page it will be on?

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

LATEST

You don't need to, because it's the same page (presumably) as the one where the calculated field is on, so you can get that information from that field's name, which you can access using event.target.name .

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Can you give me an example?

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