5 Replies Latest reply on Sep 7, 2016 12:58 PM by try67

    Conditional If/Else statement using two conditions

    CN0001

      Hello,

       

      I am trying to write a conditional if/else statement that puts a text value in a box 3 when specific conditions in box 1 and box 2 are met. Box 1 and 2 are drop down boxes with set values.

       

      I've tried searching all over the web and have probably rewritten it at least 10 different times. At one point I was able to get it working with only one of the boxes factored into the code but my computer crashed and I lost that part.

       

      Here's what I have:

       

      var n1 = this.getField("likelihood").value:

      var n2 = this.getField("consequence").value;

       

      if ((n1.value=='N/A') && (n2.value=='N/A')) {

           event.value = 'N/A'

      } else if ((n1=='Not Likely') && (n2=='Insignificant') {

           event.value = 'Low'

      }

       

      This would continue on another 14 times to account for the various combinations that can be chosen using box 1 and box 2. I have also tried placing it in the 2nd combo box as an action item but still no luck. Any help would be much appreciated.

        • 1. Re: Conditional If/Else statement using two conditions
          try67 MVP & Adobe Community Professional

          n1 and n2 are already the value of the fields, so why are you trying to access the value property again in the first if-statement?

          • 2. Re: Conditional If/Else statement using two conditions
            CN0001 Level 1

            Oops that's a typo. It should say n1 and n2 like the else if statement.

            • 3. Re: Conditional If/Else statement using two conditions
              try67 MVP & Adobe Community Professional

              So post the actual code, and also specify where you're using it. The code you posted above should be used a custom calculation script of some field.

              • 4. Re: Conditional If/Else statement using two conditions
                CN0001 Level 1

                Here is the code:

                 

                var n1 = this.getField("likelihood").value;

                var n2 = this.getField("consequence").value;

                 

                if ((n1=='N/A') && (n2=='N/A')){

                    event.value = 'N/A'

                } else if ((n1=='Not Likely') && (n2=='Insignificant')){

                    event.value = 'LOW'

                } else if ((n1=='Not Likely') && (n2=='Minor')){

                    event.value = 'LOW'

                } else if ((n1=='Not Likely') && (n2=='Moderate')){

                    event.value = 'LOW'

                } else if ((n1=='Not Likely') && (n2=='Major')){

                    event.value = 'MEDIUM'

                } else if ((n1=='Low Likelihood') && (n2=='Insignificant')){

                    event.value = 'LOW'

                } else if ((n1=='Low Likelihood') && (n2=='Insignificant')){

                    event.value = 'LOW'

                } else if ((n1=='Low Likelihood') && (n2=='Moderate')){

                    event.value = 'MEDIUM'

                } else if ((n1=='Low Likelihood') && (n2=='Major')){

                    event.value = 'MEDIUM'

                } else if ((n1=='Likely') && (n2=='Insignificant')){

                    event.value = 'LOW'

                } else if ((n1=='Likely') && (n2=='Minor')){

                    event.value = 'MEDIUM'

                } else if ((n1=='Likely') && (n2=='Moderate')){

                    event.value = 'HIGH'

                } else if ((n1=='Likely') && (n2=='Major')){

                    event.value = 'HIGH'

                } else if ((n1=='Highly Likely') && (n2=='Insignificant')){

                    event.value = 'LOW'

                } else if ((n1=='Highly Likely') && (n2=='Minor')){

                    event.value = 'MEDIUM'

                } else if ((n1=='Highly Likely') && (n2=='Moderate')){

                    event.value = 'HIGH'

                } else if ((n1=='Highly Likely') && (n2=='Major')){

                    event.value = 'HIGH'

                }

                 

                I had it in the validation script, moved it to custom calc script and still didn't work. It's being used in box 3 which should show the rating based on the choices in n1 and n2.

                 

                I have also tried using it in the second drop down box (n2) as an action item for mouse blur so it would update after the user made a choice in the last drop down.

                • 5. Re: Conditional If/Else statement using two conditions
                  try67 MVP & Adobe Community Professional

                  - Keep it as the custom calculation script.

                  - Add this line to the end of your code:

                  else event.value = "SOMETHING ELSE";

                  - Check the JS console for error messages.

                   

                  If all of that fails then you'll need to share the file with us for additional help.