Skip to main content
Inspiring
November 4, 2016
Answered

I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!

  • November 4, 2016
  • 7 replies
  • 648 views

//Uses the input from the Trailer Drop Wieght field to determine how much to subtrack from the Drop Wieght input to calculate Heel Pounds

var heel = this.getField("DWieght").value;

if (heel>0) {

     if (this.getField("Trailer").value == '86001') {
         event.value = heel-22040;
}
     if (this.getField("Trailer").value == '86002') {
         event.value = heel-22700;
}
     if (this.getField("Trailer").value == '4742')  {
         event.value = heel-22480;
}
     if (this.getField("Trailer").value == '86003') {
         event.value = heel-22480;
}
     if (this.getField("Trailer").value == '86004') {
         event.value = heel-22300;
}
     if (this.getField("Trailer").value == '86005') {
         event.value = heel-22580;
}
     if (this.getField("Trailer").value == '86006') {
         event.value = heel-22320;
}
     if (this.getField("Trailer").value == '86007') {
         event.value = heel-21980;
}
     if (this.getField("Trailer").value == '86008') {
         event.value = heel-23180;
}
     if (this.getField("Trailer").value == '4180')  {
              event.value = heel-13090;
}           
     if (this.getField("Trailer").value == '85012') {
              event.value = heel-16000;
}
     if (this.getField("Trailer").value == '8058')  {
              event.value = heel-22480;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T602')  {
              event.value = heel-14060;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T-602') {
              event.value = heel-14060;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T603')  {
              event.value = heel-16420;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T-603') {
              event.value = heel-16420;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T610')  {
              event.value = heel-21900;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T-610') {
              event.value = heel-21900;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T611')  {
              event.value = heel-20940;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T-611') {
              event.value = heel-20940;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T621')  {
              event.value = heel-17180;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T-621') {
              event.value = heel-17180;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T702')  {
              event.value = heel-19900;
}
     if (this.getField("Trailer").value.toUpperCase() == 'T-702') {
              event.value = heel-19900;
}
     if (this.getField("Trailer").value.toUpperCase() == '2R339') {
              event.value = heel-11280;
}
     if (this.getField("Trailer").value.toUpperCase() == '2R338') {
              event.value = heel-11200;
}
     if (this.getField("Trailer").value.toUpperCase() == '2R357') {
              event.value = heel-11200;
}
     if (this.getField("Trailer").value.toUpperCase() == '2R358') {
              event.value = heel-11200;
}
     if (this.getField("Trailer").value.toUpperCase() == '1R793') {
              event.value = heel-13360;
}
     if (this.getField("Trailer").value.toUpperCase() == '1R504') {
              event.value = heel-13200;
}
     if (this.getField("Trailer").value.toUpperCase() == '1R553') {
              event.value = heel-13300;

     if (this.getField("Trailer").value.toUpperCase() == '1R761') {
              event.value = heel-13360;         
}
    else event.value = "";
}

This topic has been closed for replies.
Correct answer gkaiseril

I added some code to display the adjusted heel value at the trailer choice and it appears your if statements are not coded correctly. The "else" option only applies to the last "if" statement. All your "if" statements after the first one should be "else if".

You can simplify your coding by creating a variable instead of repeatedly using the "this.getField("Trailer").value" and if you were create the variable using "this.getField("Trailer").valueAsString.toUpperCase()" you do not need to modify the value of the "Trailer" field any where else. Note that changing number or digits to upper case does not change the value since the upper case value for a digit is still the digit.

I would also add code to remove the "-" from the "Trailer" value and then some statements could be removed.

You can create an "if" statement with multiple test by using the logical OR ("||") to eliminate some test if the adjustment is the same for different trailer values.

My adjusted code:

//Uses the input from the Trailer Drop Wieght field to determine how much to subtrack from the Drop Wieght input to calculate Heel Pounds;

event.value = 0; // clear the field's value;

var heel = this.getField("DWieght").value;

// get type of trailer as a string and in upper case;

var trailer = this.getField("Trailer").valueAsString.toUpperCase();

// remove "-";

trailer = trailer.replace(/-/, "");

if (heel>0) {

     if (trailer == '86001') {

         event.value = heel-22040;

}

     if (trailer == '86002') {

         event.value = heel-22700;

}

     if (trailer == '4742' || trailer == '86003' || trailer == '8058')  {

         event.value = heel-22480;

}

     if (trailer == '86004') {

         event.value = heel-22300;

}

     if (trailer == '86005') {

         event.value = heel-22580;

}

     if (trailer == '86006') {

         event.value = heel-22320;

}

     if (trailer == '86007') {

         event.value = heel-21980;

}

     if (trailer == '86008') {

         event.value = heel-23180;

}

     if (trailer == '4180')  {

              event.value = heel-13090;

}

     if (trailer == '85012') {

              event.value = heel-16000;

}

     if (trailer == 'T602')  {

              event.value = heel-14060;

}

     if (trailer == 'T603')  {

              event.value = heel-16420;

}

     if (trailer == 'T610')  {

              event.value = heel-21900;

}

     if (trailer == 'T611')  {

              event.value = heel-20940;

}

     if (trailer == 'T621')  {

              event.value = heel-17180;

}

     if (trailer == 'T702')  {

              event.value = heel-19900;

}

     if (trailer == '2R339') {

              event.value = heel-11280;

}

     if (trailer == '2R338' || trailer == '2R357' || trailer == '2R358') {

              event.value = heel-11200;

}

     if (trailer == '1R793') {

              event.value = heel-13360;

}

     if (trailer == '1R504') {

              event.value = heel-13200;

}

     if (trailer == '1R553') {

              event.value = heel-13300;

}

     if (trailer == '1R761') {

              event.value = heel-13360;

}

} // end if heel not zereo;

You could also use the "switch" statement to eliminate the nested "if" statements.

7 replies

try67
Community Expert
Community Expert
November 4, 2016

What does "it stopped working" mean, exactly? Also, what application are you using to open the file?

DuquetteAuthor
Inspiring
November 4, 2016

I am using it to calculate product heel on different trailers from an adobe form on acrobat. As far as not working - it no longer calculates the product heel when the other parameter "DWieght" and "Trailer" fields are populated. I can not find anything wrong with the code and just stopped working two days ago.

try67
Community Expert
Community Expert
November 4, 2016

Are you 100% sure you're opening the file in Acrobat and not in some other

application, or a browser window? Also, what exact version of Acrobat is it?

Can you share with us the file involved (via Dropbox, Google Drive, Adobe

Cloud, etc.)?