5 Replies Latest reply on Jun 7, 2008 2:00 PM by (EJ_Drake)

    Calculation Not Working Correctly  - Desperately Need Assistance

      I am working in Acrobat Pro V8 and am having a problem with a result from my calculation script running a step behind. Let me preface this by stating that I have read numerous posts on SETTING THE CALCULATION ORDER and it appears this would be the problem here. However, the calculation order is correct. Determining this total is the last thing to happen and it is the last item in the "Set Field Calculation Order".

      Basically, I have an Exceeds total field, which is a calculation of the value in one field less the value in another field. If the result from this calculation is greater than "1", two additional fields (one read only text; one hidden signature field) should become visible because the document would require approval - if the end result is 0 or a negative number ... no signature is required. Anyway, the calculation works, but only if a second number is entered after entering the number that should have caused it to work. (Sorry if that sounds a bit confusing.)

      My Exceeds total script is a Custom Calculation Script and is as follows:

      var a=this.getField("TotalActual").value;

      var b=this.getField("OrigEstExpense").value;
      // set event value to b-a if "a - b > 0" : else set it to 0
      event.value = a - b > 0? a-b : 0;

      if(event.value == 0) event.value = "";

      var f1 = this.getField("ExceedsOrig").valueAsString;
      var f2 = this.getField("ExceedSign");
      var f3=this.getField("ExceedsStmt");

      if ( f1 >= 1)
      {
      f2.hidden=false; f3.hidden=false;
      }
      else
      {
      f2.hidden=true; f3.hidden=true;

      }

      I have also tried placing a document level script to call the function from within one of the fields that should be visible or not, but it too is a step behind and I've tried pasting the latter portion of the above script as a javascript in my text and signature field, which doesn't work either.

      I would be most appreciative if someone could shed some light on this as it does not appear to be a problem with the calculation order.

      I've been racking my brain and admit that I am pretty new at this, but this is mind-boggling.
        • 1. Re: Calculation Not Working Correctly  - Desperately Need Assistance
          gkaiseril MVP & Adobe Community Professional
          If you are converting a number to a character string, you should compare to a string value and not a numeric value. Also you are not testing the current value of the computed field but the previous value. Try the following script and enter a series of different values and observe the result in the console window.

          var a=this.getField("TotalActual").value;
          var b=this.getField("OrigEstExpense").value;
          // set event value to b-a if "a - b > 0" : else set it to 0
          event.value = a - b > 0? a - b : 0;
          event.value = event.value == 0? "" : event.value

          var f1 = this.getField("ExceedsOrig").valueAsString;
          var f2 = this.getField("ExceedSign");
          var f3=this.getField("ExceedsStmt");

          console.show(); console.clear();
          console.println("event.value: " + event.value);
          console.println("Number(event.value): " + Number(event.value));
          console.println("ExceedsOrig: " + f1);
          console.println("f1 >= 1: " + ( f1 >= 1) );
          console.println("f1 >= \"1\": " + ( f1 >= "1") );
          console.println("event.value >= 1: " + ( event.value >= 1) );
          console.println("event.vlaue >= \"1\": " + ( event.value >= "1") );

          if (event.value >= 1) {
          f2.hidden=false; f3.hidden=false;
          } else {
          f2.hidden=true; f3.hidden=true;
          }

          The field value does not update until the field loses focus, so you should be using the "event.value".
          • 2. Re: Calculation Not Working Correctly  - Desperately Need Assistance
            Level 1
            You are AWESOME! I don't think I would have ever figured that one out. It's so nice of you to share your knowledge, newbies like me are learning a lot from you.

            Obviously, this works exactly as it should. YEAH!!!!!!!!!! Thank you, thank you, thank you!
            • 3. Re: Calculation Not Working Correctly  - Desperately Need Assistance
              OK - I have a similar problem and you may have partially hit on a solution.

              I have a javascript calculation on two fields in a list.
              The list is then totalled using a normal field calculation (not javascript).

              The javascript calculation is working fine and yes, I am using event.value.

              BUT, the list calculation WILL NOT OCCUR until another number is input somewhere else in the form.

              The calc is here:
              var f = this.getField("Text22");
              event.value = Math.round(f.value * -1);

              I agree that it feels like a field focus issue.
              Is there any way to issue a command to lose the focus?
              • 4. Re: Calculation Not Working Correctly  - Desperately Need Assistance
                Patrick Leckey Level 3
                Does it only happen when another number is input somewhere else, or does it happen as soon as the field loses focus (i.e. if you tab out of the field but do not change any other numbers anywhere else)?
                • 5. Re: Calculation Not Working Correctly  - Desperately Need Assistance
                  Level 1
                  To be clear: The javascript calculation is working immediatelty.

                  The TOTAL computation will NOT occur if you tab, Enter, or whatever away from the javascript computation field. In order to get the TOTAL to recalculate, you have to input a number or any other data in any field on the form, then hit Enter or Tab.

                  I just found that this is also happening to fields using the built in MULTIPLY computation. It does not seem to happen to SUM.

                  Now, clearing a field updates the TOTAL immediately.

                  (Adobe: I wonder if this is a Little Endian issue as I am on a Powermac G4? Have not had a chance to try it on another machine.)