4 Replies Latest reply on Jun 11, 2015 1:11 PM by George_Johnson

    Calculation script

    Trendyfroggy

      Hello,

       

      Could someone help me translate this into Java Script Calculation. This is giving me a hard time. Any help would be appreciated.

       

      I am trying to set the calculation field for a field called f2.  In essence this is what I am trying to instruct this field to calculate.

       

      1. Leave f2 blank if fields a2 , d2 and e2 have no value yet.

       

      2. if a2 is a negative number, then the value of f2 is the same as the value of f1.

       

      3. if a2 is a positive number, then f2 equals   d2 divided by e2.

       

      Please Help ;-)

        • 1. Re: Calculation script
          gkaiseril MVP & Adobe Community Professional

          A couple of missing pieces of information.

           

          What do you want to do when field a2 is neither negative nor positive? Zero is neither negative nor positive, it is just zero.

           

          What do you want to do when e2 is zero? Division by 0 is considered undefined in arithmetic but could take on other values in more advanced mathematical calculations.

           

          // custom calculation for field f2 (event);
          function GetField(cName) {
          // get the field object for the named field with error checking;
          var oField = this.getField(cName);
          if(oField = null) {
          app.alert("Error accessing field " + cName + \nCheck that field exist and it the correct name", 1, 0);
          return oField;
          } // end GetField function;

          // get the field objects for the needed fields;
          var oA2 = GetField("a2");
          var oD2 = GetField("d2");
          var oE2 = GetField("e2");
          var oF1 = GetField("f1");
          event.value = "";
          if(oA2.valueAsString == "" && oD2.valueAsString == "" && oE2.valueAsString != "") {
          // Leave f2 blank if fields a2 , d2 and e2 have no value yet.;
          event.value = "";
          }

          if(oA2,value < 0) {
          // if a2 is a negative number, then the value of f2 is the same as the value of f1;;
          event.value = oF1.value;
          } // end negative a2 processing;

          if(oA2 == 0) {
          // do something when a2 is neither negative or positive, i.e. zero.
          } // end a2 neither negative nor positive processing;

          if(oA2 > 0) {
          // 3. if a2 is a positive number, then f2 equals   d2 divided by e2;
          if(oE2.value != 0){
          // make sure divisor is not zero;
          event.value = oD2/ oE2;
          } else {
          // do something when field e2 is zero;
          } // e2 zero processing;
          } // end a2 positive processing;

          • 2. Re: Calculation script
            Trendyfroggy Level 1

            Hello,

            When a2  -  d2  or e2 is zero, leave f2 blank

            ;-)

            • 3. Re: Calculation script
              Trendyfroggy Level 1

              I am getting a Syntax Error: illegal character

              6: at line 7  with the genious script you provided ;-)

              • 4. Re: Calculation script
                George_Johnson MVP & Adobe Community Professional

                For a start, these two lines:

                 

                if(oField = null) {

                app.alert("Error accessing field " + cName + \nCheck that field exist and it the correct name", 1, 0);


                Should be:


                if(oField == null) {

                app.alert("Error accessing field " + cName + "\nCheck that field exist and it the correct name", 1, 0);