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

Script for true or false answer?

New Here ,
Jan 02, 2017 Jan 02, 2017

Hi!

I'm trying to get a field to print a true or false answer. The field is supposed to get data from another field (which is a summary field) and state if its 65 or above and then print if it is or not.

I have tried the following script but cannot get it to work.

{

if (this.getField(” Summa ATS 1”) == 65 = true);

if (this.getField(” Summa ATS 1”) < 65 = true);

if (this.getField(” Summa ATS 1”) > 65 = false);

{

if (true) System.out.println(" True ");

if (false) System.out.println(" False ");

}

How can I get this to work?

TOPICS
Acrobat SDK and JavaScript
1.2K
Translate
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 ,
Jan 02, 2017 Jan 02, 2017

There are several major mistakes in your code.

First of all, the "=" operator is used for assigning a value, not for comparisons.

Also, you should not use curly quotes in your code. Only straight ones (single or double, doesn't matter).

In addition, you should not put a semi-colon after an if-statement. It basically renders it useless. It should be followed either by a single line of code or by a block of code, surrounded by curly brackets, which are executed when that expression is true.

You should also be aware that any logical operator will always return a Boolean value, that is either true or false, so there's no need to add an additional check to check if it's true...

This line:

if ((a==b)==true)

Is identical to this line:

if (a==b)

PS. Just noticed another problem. You're only accessing the fields themselves, not their values...

Translate
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
New Here ,
Jan 02, 2017 Jan 02, 2017

Hi!

Thank you for the answer.

I guess this code should be right then:

if (this.getField("Summa ATS 1").value < 64)

{

System.out.println("OK")

}

​But it doesn't print "OK"!?

Translate
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 ,
Jan 02, 2017 Jan 02, 2017

From where are you executing the code?

Are there any error messages?

Translate
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
New Here ,
Jan 02, 2017 Jan 02, 2017

No error messages, but still not the result I'm after.

Don't know if this print screen helps, it's in Swedish.

printscreen.jpg

Translate
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 ,
Jan 02, 2017 Jan 02, 2017

Can you share the file itself, via Dropbox, Google Drive, etc.?

Translate
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
New Here ,
Jan 02, 2017 Jan 02, 2017

Sure I can.

Via Google Drive, who to invite?

Translate
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 ,
Jan 02, 2017 Jan 02, 2017
LATEST

See the comment above. You're using incorrect commands (this is JavaScript, not Java!).

Try it again using console.println() and if it still doesn't work make the file public and post the link to it here.

Translate
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
LEGEND ,
Jan 02, 2017 Jan 02, 2017

I am not familiar with "System.out.println ()" in Acrobat JavaScript. There is the :console.println ()" to print to the JavaScript console or the "app.alert ()" for a pop-up message.

Do you get any error message on Acrobat's JavaScript console?

You should be using JavaScript statements. Acrobat does not use Java  which is a very different language.

Translate
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