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

Document Level Scripts for Template Calculations - Best Practices?

Community Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

I have a page with calculations that may need to be spawned multiple times. I'm trying to sort out the most efficient approach to modifying the fields in the template.

 

Example: There are about 40+ fields that use the following calculation which I wrote as a document level function:

BasalArea

function BasalArea()

{

// Find field name suffix for current line

var fld = this.getField(event.target.name)

var sf = event.target.name.split(".").pop();

 

// Establish variables

var r = Math.PI

var diam = "F2a.DBH." + sf;

 

// Perform calculation

event.value = (r * Math.pow(this.getField(diam).value,2))/40000

}

 

I also created the following document level script to aquire the field name prefix on spawned pages:

 

PreFix

function PreFix()

{

// Extract prefix for fields on spawned page 

var cPreFix

var aFieldName = event.target.name.split(".");

if(aFieldName.length > 2)

 

// First 2 elements of name array make up the prefix;

    (cPreFix = aFieldName[0] + "." + aFieldName[1] + ".");

else cPreFix = "";

return cPreFix

}

 

The template itself is a copy of the original page which is hidden and I have renamed the fields slightly on the template so that they are not linked (maybe that was unnecessary since they will be again renamed when the template spawns, but I was having trouble working on the document with identical field names).

 

So I will create a modified calculation script for the template (using the modified field names) called

function tptBasalArea() 

 

So here are my questions:

1) Can a document level function reference another document level function? Can tptBasalArea() reference PreFix() or should the script for PreFix() be built into tptBasalArea()?

 

2) Is there a better place for a script that is only used by that template, like a page level script?

 

3) Have I created unnecessary inefficiencies that will slow everything down?

 

TOPICS
How to , JavaScript , PDF forms

Views

179

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

Copy link to clipboard

Copied

LATEST

1) Yes, it can.

2) At the page level you can only assign code to the page's Open and Close events, but I wouldn't use those for this purpose. The rest of the scripts are either at the App, Document or Field/Bookmark/Link levels. For your purposes I think keeping it at the doc-level is the best option.

3) It seems fine to me.

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