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

What event does calculation?

Gattaca714
Registered: Dec 16 2009
Posts: 25
Answered

I know this may sound like a dumb question but I have this code under calculate:
 
var a = get.thisField("fldYesYellowEnvelope").value;
var b = get.thisField("fldYesWhiteEnvelope").value;
var c = get.thisField("fldCurrentPVBMCount").value;

event.value = a + b + c;
 
This is a numeric field.
 
I'm completely stumped as to why it wont auto calculate.

My Product Information:
LiveCycle Designer, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You have a typo, and for numerical addition you should explicitly convert the field values to numbers so you don't get string concatenation in the case of empty fields. You can convert to a number using the unary + operator. Try this:

var a = +getField("fldYesYellowEnvelope").value;
var b = +getField("fldYesWhiteEnvelope").value;
var c = +getField("fldCurrentPVBMCount").value;

event.value = a + b + c;

or better yet:

(function () {

var a = +getField("fldYesYellowEnvelope").value;
var b = +getField("fldYesWhiteEnvelope").value;
var c = +getField("fldCurrentPVBMCount").value;

event.value = a + b + c;

})();

...to prevent the unnecessary creation of document-global variables.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If you are using LiveCycle Designer you can also use the FormCalc code:

fldYesYellowEnvelope + fldYesWhiteEnvelope + fldCurrentPVBMCount

Are you getting and error messages?

In "Preview" open the JavaScript Debugging console of Acroaat with the key combination " + J"

George Kaiser

Gattaca714
Registered: Dec 16 2009
Posts: 25
I get this error:

script failed (language is formcalc; context is xfa.

Error: access 'fldYesYellowEnvelope' is unknown
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Your original code was for a form created in Acrobat, not LiveCycle Designer. That's the reason your code isn't working. You can use FormCalc as suggested above, or learn the equivalent JavaScript for XFA. There are several tutorials here that should help.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You could also change the scripting language to "JavaScript" within LiveCycle Designer. And use the follwing script:

var a = fldYesYellowEnvelope.rawValue;
var b = fldYesWhiteEnvelope.rawValue;
var c = fldCurrentPVBMCount.rawValue;
event.rawValue = a + b + c;


George Kaiser

Gattaca714
Registered: Dec 16 2009
Posts: 25
This worked:

IFS.Page5.fldVbmEnvelopeOrderQty0 = IFS.Page4.fldYesYellowEnvelope + IFS.Page5.fldYesWhiteEnvelope + IFS.Page4.fldCurrentPVBMCount;


Data Format has to be an interger not float for every field.

Had to reference the document name and page number and field.

This is a FormCalculation. Hope this helps out someone in the future.