Skip to main content
Known Participant
April 5, 2021
Answered

Calculations in template with renamed fields?

  • April 5, 2021
  • 1 reply
  • 632 views

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.

This topic has been closed for replies.
Correct answer try67

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 .

1 reply

try67
Community Expert
Community Expert
April 5, 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.

eshrimpsAuthor
Known Participant
April 5, 2021

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 5, 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 .