1 Reply Latest reply on May 7, 2016 4:45 AM by Karl Heinz Kremer

    Conditional statement

    k8f8

      Need help with a conditional statement, please.   If calculated field1 minus calculated field2 is greater than zero, I want the result to show in field3.  If the result is less than zero, I want the result to show in field4.  Anyone?  Thanks!

        • 1. Re: Conditional statement
          Karl Heinz Kremer Adobe Community Professional

          There are different ways to do this. You can for example create a separate calculation script for Field3 and another one for Field4. In this case, I would however combine both calculations and create just one calculation script. The following script, when used as the custom calculation script for Field3 will do what you ask for:

           

          var f1 = this.getField("Field1");
          var f2 = this.getField("Field2");
          var f4 = this.getField("Field4");
          
          
          if (f1.valueAsString != "" && f2.valueAsString != "") {
              var diff = f1.value - f2.value;
              if (diff > 0) {
                  event.value = diff;
                  f4.value = "";
              }
              else {
                  event.value = "";
                  f4.value = diff;
              }
          }
          else {
              event.value = "";
              f4.value = "";
          }
          
          1 person found this helpful