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

Calculating Field Values

ebbo1983
Registered: Mar 16 2009
Posts: 93

Hello I have a PDF file with 2 pages and 3 fields in total, I need to add together two of the fields to get the net_asset_total. The 2 fields that are to be added together are actually subtotals themselves of other calculations. See below

[color=RED]Page 1: field: t1_total_voa

----- topmostSubform.Page1.t1_total_voa::calculate: - (JavaScript, client) -------------------------

this.rawValue = t1_voa1.rawValue + t1_voa2.rawValue + t1_voa3.rawValue + t1_voa4.rawValue + t1_voa5.rawValue + t1_voa6.rawValue + t1_voa7.rawValue;[/color]

[color=BLUE]Page 2: field: t2_total_lia

----- topmostSubform.Page2.t2_total_lia::calculate: - (JavaScript, client) -------------------------

this.rawValue = t2_amount_lia1.rawValue + t2_amount_lia2.rawValue + t2_amount_lia3.rawValue + t2_amount_lia4.rawValue;[/color]

[color=GREEN]Page 2: field: net_asset_total

----- topmostSubform.Page2.net_asset_total::calculate: - (JavaScript, client) ----------------------

this.rawValue = t1_total_voa.rawValue + t2_amount_lia2.rawValue;[/color]

[b]RESULT:[/b]
Script failed (language is javascript; context is xfa[0].form[0].topmostSubform[0].Page2[0].net_asset_total[0])
script=this.rawValue = t1_total_voa.rawValue + t2_amount_lia2.rawValue;
Error: t1_total_voa is undefined

It seems it doesnt like to calculate over different pages, how can I do this? And also is there an easy way to calculate, this is just some code I found on google and it worked up until this point, so if there is a better way, i would appreciate it if you could let me know.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
If you are accessing fields in a different subform you have to use the full reference including the subform to reference the fields on the other subform.

George Kaiser

ebbo1983
Registered: Mar 16 2009
Posts: 93
Is it possible for you to give an example please? I know what you are trying to say, I just dont know how to do it
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi ebbo1983,

The hierarchy of fields and using their SOM paths in scripts is covered in the on demand e-seminar here at AUC titled "Extending LiveCycle Forms with JavaScript and FormCalc"
https://admin.adobe.acrobat.com/_a200985228/p87746471/

Longer and more detailed videos on scripting in LiveCycle Designer can be found at www.pdfscripting.com

It is always better to understand how and why scripts work than to just copy and paste someone else's code.

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
ebbo1983
Registered: Mar 16 2009
Posts: 93
Thanks, I spent an hour studying this tutorial, quite useful.

I now know how to pick up values accross different forms, and my form is working.

Aside from 1 minor detail, i need some help with javascript now, so I hope somebody can help.


This is my calculation:

net_asset_total.rawValue = topmostSubform.Page1.t1_total_voa.rawValue - topmostSubform.Page2.t2_total_lia.rawValue;

And what I need to do in terms of logic is:

IF

t1_total_voa - t2_total_lia

is less then 0

THEN

net_asset_total should be set to 0

ELSE

net_asset_total should remain unchanged

echo net_asset_total


This is my sorry attempt at programming:

net_asset_total.rawValue = topmostSubform.Page1.t1_total_voa.rawValue - topmostSubform.Page2.t2_total_lia.rawValue;

var a;

a.rawValue = net_asset_total.rawValue;

if (a.rawValue <0)
{
a.rawValue = 0;
net_asset_total.rawValue = a.rawValue;
}
else
{
net_asset_total.rawValue = a.rawValue;
}
net_asset_total.rawValue;