Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

I need help with a script

Avatar

Level 4

I have a form where I need one field to subtract from another but never show a negative number in the result field. So if the first field AsstsMo1 is $100 and the second field SubDis1 is $200, I don't want the negative $100 to show in the total field but to display a zero instead. 

This is what I have so far in FormCalc. It works but doesn't display a zero in the field where it should but does display a zero in a field that calculates off this field. So the field is called Excess1 and that's where the script is assigned to and later on in the form, a total field calls for Excess1 to be added to MonthlyExcess1 and that's where the zero displays which is perfect. I just can't get the first field to display that zero. Right now it displays nothing.

if(SubDis1 >= AsstsMo1) then $.rawValue = AsstsMo1 - AsstsMo1 else $.rawValue = AsstsMo1 - SubDis1 endif

Can you help?

6 Replies

Avatar

Level 10

Hi,

The script looks okay-ish, I am just replicating it here with some amendments:

if (SubDis1 ge AsstsMo1) then

     $ = 0

else

     $ = AsstsMo1 - SubDis1

endif

In FormCalc the equivalent operator is "ge" for greater than or equal to. Make sure that the language is set to FormCalc.

Give that a try,

Niall

Avatar

Level 4

That gave me quite a few errors when I opened it in Acrobat Pro and still didn't display a zero.  Here is what it displayed:

Script failed (langage is formCalc; context is xfa[0].form[0].form1[0],Page [0].Spenddown[0].Excess1[0])

script= (then the script)

Error: syntax error near token "on line 2, column 4294957295 (whatever that means)

Avatar

Level 10

Hi,

If you open the JavaScript Console it may show the error in more detail:

Javascript Console.png

From the error we know that you have the correct language.

The problem is on line 2. I would recommend that you go to the Script Editor and click on the Check Syntax button above the script editor. This should hlightline the error in red. Also if you go to the Warnings palette you may get further information there.

The script doesn't have a double quotation mark, so unless there is a stray one in the script it is difficult to see ehat is wrong.

Can you share your form?

Niall

Avatar

Level 10

Hi,

You can upload it to Acrobat.com and then post your published file URL here:

Acrobat.com publish.png

Niall

Avatar

Level 4

Ok, here it is. The first column is where I'm trying to get the script to work in the field that says: Excess Assets. This is the field that I want to show a zero if the number calculated is a negative. That field also is scripted to the field at the bottom that says: "Your Monthly Resource Spenddown" so whatever appears in the Excess Assets field should also be calculated into the Resource spenddown.

The second and third colums have the original scripting that would create a negative number in those fields and that's what they want to change. Thanks for your help.

https://acrobat.com/#d=sguaGdBIkGAYgvkHIGbUeA