7 Replies Latest reply on Nov 7, 2016 9:11 PM by Duquette

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

    Duquette

      //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 = "";
      }

        • 1. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
          try67 MVP & Adobe Community Professional

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

          • 2. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
            Duquette Level 1

            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.

            • 3. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
              try67 MVP & Adobe Community Professional

              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.)?

              • 4. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
                gkaiseril MVP & Adobe Community Professional

                What has changed on your system since you started using this code?

                 

                New OS?

                 

                New version of Acrobat?

                 

                Some other change to the form?

                 

                Have you checked the JavaScript console for errors?

                 

                Since the field "Trailer" has some values that are numbers and not text and numbers, I would use the "valueAsString"" property and not the "value" property.

                 

                You could temporarily add some code to see if the code is being run by adding some "console.prinlt("some message");" to the script.

                • 5. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
                  gkaiseril MVP & Adobe Community Professional

                  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.

                  • 6. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
                    gkaiseril MVP & Adobe Community Professional

                    Download Compute Heel Weight for a working form that has code for using the "if" statement, the "if ... else " statement, and the switch statement.

                    • 7. Re: I have used this code for several years and suddenly it stopped working - Cant' figure out why. Please Help!
                      Duquette Level 1

                      Thank You, you suggestions not only solved my problem, but made the code more efficient.