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

How do I convert the following Document level JS into a script in the document?

Participant ,
May 12, 2016 May 12, 2016

Here is the DLJ (Document Level Javascript) I want to convert to a script in a field in the document:

function getRanksValue(doc, name) {

    var rank = doc.getField(name).value;

    var value = 0;

    if (rank < 1) {

        value = -25;

    } else if (rank > 20) {

        value = 10 * 5 + 10 * 2 + (rank - 20);

    } else if (rank > 10) {

        value = 10 * 5 + (rank - 10) * 2;

    } else {

        value = rank * 5;

    }    return value;

}

The following is the script in a "Consolidated Script" field, where line 2 has the script that calls that DLJ:

for (var i=0;i<115;i++)

  this.getField("Rank Bns."+i).value = getRanksValue(this, "Ranks"+i);

  for (var ii=0;ii<115;ii++)

  this.getField("Total Bns."+ii).value = Number(this.getField("Rank Bns."+ii).value) + Number(this.getField("Stat Bns."+ii).value)

  + Number(this.getField("Spec Bns."+ii).value);

  this.getField("Total Bns.44").value = Number(racialStatMods[this.getField("Race").value][10])

  + Number(this.getField("Rank Bns.44").value) + (this.getField("Stat Bns.44").value) + Number(this.getField("Spec Bns.44").value);

  this.getField("Total Bns.45").value = Number(racialStatMods[this.getField("Race").value][11])

  + Number(this.getField("Rank Bns.45").value) + Number(this.getField("Stat Bns.45").value) + Number(this.getField("Spec Bns.45").value);

  this.getField("Total Bns.46").value = Number(racialStatMods[this.getField("Race").value][12])

  + Number(this.getField("Rank Bns.46").value) + Number(this.getField("Stat Bns.46").value) + Number(this.getField("Spec Bns.46").value);

It works as is but I am thinking it might be a little faster if I were to convert the DLJ to work in place of the script in the second section of line 02 above where it calls the DLJ. It would remove the need to call the DLJ. I have been trying to figure this out not for a few hours and I have not gotten anywhere.

I hope someone can help me.

TOPICS
Acrobat SDK and JavaScript
2.5K
Translate
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
New Here ,
Jun 11, 2016 Jun 11, 2016
LATEST

Support for all video players options

Translate
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