2 Replies Latest reply on Apr 13, 2011 12:33 PM by dryse

    If statement comparing fields




      I have a field in which I am trying to compare two calculated fields, then enter one of two choices. Example


      If A1 < B1 then enter A1.value, else enter B1.value


      I know very little about scripting and thank goodness I've found most of what I need here on the forum.  What is the script I would need to use to accomplish this task?


      Thank you!

        • 1. Re: If statement comparing fields
          George_Johnson MVP & Adobe Community Professional

          A custom calculate script for the third calculated field could look like:


          (function () {
              // Get the field values, as numbers
              var v1 = +getField("A1").value;
              var v2 = +getField("B1").value;
              // Set this field's value
              if (v1 < v2) {
                  event.value = v1;
              } else {
                  event.value = v2;



          The "if" block could be simplified to just:


              // Set this field's value
              event.value = v1 < v2 ? v1 : v2
          • 2. Re: If statement comparing fields
            dryse Level 1

            Thank you George!  I was close in my trials, but we all know close doesn't get the job done! Your script worked perfectly!