Skip to main content
Atom0312
Participant
April 20, 2018
Question

i am trying to enter this Excel formula into a Java Script however I have no clue how to use Java

  • April 20, 2018
  • 3 replies
  • 370 views

i am trying to enter this Excel formula into a Java Script however I have no clue how to use Java.

can anyone help me translate this please?

=IF(Text6.0=0,"X",IF(Text6.0<=13,"Low Risk",IF(Text6.0<=19,"Medium Risk",IF(Text6.0>=20,"High Risk","X"))))  

I have changed the Excel cell numbers to the correct names of the Acrobat form fields.

The Acrobat i am using is Pro DC.

Thanks!

This topic has been closed for replies.

3 replies

Inspiring
April 30, 2018

In order to help you, I need to understand what you are trying to achieve. There are several ways to script what you are describing.

here is one:

//Copy all this script in the calculate tab of the result field

//Isolate the value we are going to test

var myScore = this.getField("Text6.0").value

//Then we test the value against your conditions

//This part will take care of anything less than 20

switch(myScore){

case 0:

     event.value = "X"

     break

case 1:

case 2:

case 3:

case 4:

case 5:

case 6:

case 7:

case 8:

case 9:

case 10:

case 11:

case 12:

case 13:

     event.value = "Low Risk"

     break

case 14:

case 15:

case 16:

case 17:

case 18:

case 19:

     event.value = "Medium Risk"

     break

}

//This handles a value of 20 or more

if (myScore >= 20) event.value = "High Risk"

//this handles an empty field or the last part of your excel formula

if (myScore == "") event.value = "X"

We could also have gone with the same identation as you did in excel but it is not easy on the eye.  3 levels of Identation is about the maximum before your code gets un-readable.

//this is not a real code, just a representation

if (some condition){

               //do that

}

else{

               if (some condition){

                                   //do that

                }

               else

                                   if (some condition){

                                                          // do that

                                    }

                                     else{

                                                          if (some condition){

                                                                           //do that

                                                            }

                                                            else{

                                                                            //do that

                                                                }                   

                                       }

                    }

}

Finally we could have used "AND" or "OR" statements just as in excel's AND() and OR()

Thom Parker
Community Expert
Community Expert
April 21, 2018
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
April 20, 2018

A good place to start learning how to do it in Acrobat JavaScript (not Java): https://acrobatusers.com/tutorials/conditional-execution