These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

custom calculation not working

nahpishtim
Registered: Oct 12 2009
Posts: 30

Okay so I've had quite a bit of luck with the formatting scripts but somethings wrong with the custom calculation scripts. I'm pretty sure my script is right since it's mostly a copy paste from an example I found and it doesn't give me the script error message when I save it but it will not actually calculate. I've tried a few different scripts but none work. The simplified field notation works just fine but it won't work with what I need to forms to do. Might anyone know what the problem is?

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi nahpishtim,

First off, one problem may be that you are using scripts from other sources but you may not understand why they work, the syntax used, or how to analyze a script. It can sometimes work brilliantly to copy/paste other people's work, but there are MANY MANY times where it does not. Read this blog post on some of the issues you run into copying/pasting scripts-

http://www.acrobatusers.com/blogs/thomp/copying-and-pasting-code

On another point that is really really important- How exactly can anyone here help with this when you don't say anything specific about what it is you are doing? No one here has a crystal ball, sorry.

The forums here are for helping with pin point issues. Maybe you would benefit from a training course in Acrobat JavaScript that will provide the basics you need to better understand scripting both in general and in Acrobat and PDF. Check out www.pdfscripting.com- for $39 you get over 11 hours of instruction on this topic by a leading expert (Thom Parker). I don't mean this as a blatant plug for one of my company's products- it just seems you really need some basic training for what you are doing.

Hope this helps,

Dimitri
WindJack Solutions
www.windjack.com
www.pdfscripting.com
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
As noted without a copy of the script and other information, one can not answer this question.

As an example, you can use:
app.alert('Hello World!');
As a custom calculation script and it will pop-up each time the calculation script is triggered.
But if one has:
if(bTest != 'undefined') {app.alert('Hello World!');

And the variable 'bTest' has not been defined will never work until a variable 'bTest' is defined. The 'undefined' condition of this variable has been trapped. One could also use the 'try' statement to trap errors.

Or one can define a function in the custom calculation script box:
function Hello() {app.alert('Hellow World!');return;}

And this code will not run because one needs to call the function with the statement 'Hello();'.

George Kaiser

nahpishtim
Registered: Oct 12 2009
Posts: 30
The script was variables defined for 5 forms and about a dozen if/else if's. The purpose was to check if one form read was 5 >= while the others were <= 4The base script I altered had done a similar thing with different field names I just plugged mine into it instead and hoped it would work. I've also just tried a basic one that I seen that was just a form1 + form2 one. I'd had several set up like this

if(Form1 >= 5 && Form2 && Form3 <=4)
event.value = Base + 2
else if(Form1 && Form2 >= 5 && Form3 <=4)
event.value = Base + 4
else if(Form1 && Form2 && Form3 >=5)
event.value = Base +6

It also had more options that went on to all the variables of those three forms being greater than or less than the respective values.

Also are there any actual books someone could recommend for scripting in acrobat?
rfaller
Registered: Oct 27 2009
Posts: 2
Good afternoon! May I jump in on this script? I have been searching the knowledge base for more than an hour to find a really simple fix to a really simple problem that I am not savvy enough to figure out. I have a form that is supposed to calculate a simple ProductX. I'm using two fields. One is a static number, that being Cost. The second is the "dynamic" or user field that is Quantity. My format for Quantity is to Sum+ so as to add any number in the field and then have it calculcate a total using Cost. I have the calc order being Quantity first and then the Total. All I get is 0.00 for my answer. What am I missing?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
nahpishtim wrote:
The script was variables defined for 5 forms and about a dozen if/else if's. The purpose was to check if one form read was 5 >= while the others were <= 4The base script I altered had done a similar thing with different field names I just plugged mine into it instead and hoped it would work. I've also just tried a basic one that I seen that was just a form1 + form2 one. I'd had several set up like this

if(Form1 >= 5 && Form2 && Form3 <=4)
event.value = Base + 2
else if(Form1 && Form2 >= 5 && Form3 <=4)
event.value = Base + 4
else if(Form1 && Form2 && Form3 >=5)
event.value = Base +6

It also had more options that went on to all the variables of those three forms being greater than or less than the respective values.

Also are there any actual books someone could recommend for scripting in acrobat?
It looks like you are using LiveCycle Designer JavaScript, and the syntax for that is different from Acrobat forms. In general one can not copy code from LiveCycle Designer forms to Acrobat forms.
Although it is possible to run Acrobat Application Folder scripts in LiveCycle Designer.

George Kaiser

rfaller
Registered: Oct 27 2009
Posts: 2
I have been searching the knowledge base for more than an hour to find a really simple fix to a really simple problem that I am not savvy enough to figure out. I have a form that is supposed to calculate a simple ProductX. I'm using two fields. One is a static number, that being Cost. The second is the "dynamic" or user field that is Quantity. My format for Quantity is to Sum+ so as to add any number in the field and then have it calculcate a total using Cost. I have the calc order being Quantity first and then the Total. All I get is 0.00 for my answer. What am I missing? I really need help and an answer quickly!