• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

241

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

Here are some articles on writing calculations in Acrobat JavaScript

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

https://acrobatusers.com/tutorials/conditional-execution

Calculating field values and more

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

LATEST

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()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines