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

Basic subtraction script for Livecycle

RusticRanger
Registered: Jun 14 2010
Posts: 27
Answered

I have read many posts on the subject, and most refer to Acrobat rather than Livecycle. I have tried to do a simple subtraction and multiplication combination, and am failing completely. Clearly I am doing something wrong, or am just too new at this, but please will someone help.

The calculation should be (MarkVal - BalMortgage - Penalties - SaleCosts) x PercentInt

Penalties and SaleCosts can be empty, and PercentInt is a percentage

All fields are Numeric, and the field that accepts the calculation is Equity, also numeric and the field value set to Calculated - Read Only. That field has the following script on the Calculate event - Javascript:

event.value = (this.getField(MarkVal).value - this.getField(BalMortgage).value - this.getField(Penalties).value - this.getField(SaleCosts).value) * PercentInt/100;

I get no errors, but I get no result either - any help? The only thing that might be a problem is that each of these fields is part of a Group, which is wrapped in a subform. I would attach the PDF if I could find a way.

UPDATE - removed all groups so that we now only have fields wrapped in subforms - same problem.

Livecycle ES 9.0 - Windows 7 Ultimate

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The scripting model for LiveCycle forms is very different than scripting for AcroForms. Fields are refered to directly rather than though a "getField" acquire. So your calculation would be writen like this.

In FormCalc:
MarkVal - BalMortgage - Penalties - SaleCosts) * PercentInt


In JavaScript:
MarkVal.rawValue - BalMortgage.rawValue - Penalties.rawValue - SaleCosts.rawValue) * PercentInt.rawValue;

Given of course that all the fields are in the same subform.

Notice also that "event.value" is not used.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RusticRanger
Registered: Jun 14 2010
Posts: 27
Thanks Thom - I see now that everything, including the field to accept the answer, has to be in the same subform. With the simplified script, it works well, even when I then addInstance for that subform. Thanks again for your help.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Everything doesn't have to be in the same subform. But the referenced fields have to have all the correct pathway elements between where they are used.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RusticRanger
Registered: Jun 14 2010
Posts: 27
I now have a related problem, and it appears I spoke too soon. In the subform, I have two calculated fields - the first is for the field TotEquity

MarkVal2.rawValue - BalMortgage2.rawValue - Penalties2.rawValue - SaleCosts2.rawValue;


The second (TotalB) calculates the person's equity value according to their percentage ownership

TotEquity.rawValue * TotInterest.rawValue/100;

That all works fine for the first instance. What I am now stuck with is that the form needs a separate page for each property, so I have an addInstance that duplicates the entire page, including the above subform. I need TotalB to be a running total ie. TotalB[0] + TotalB[1], etc. The difficulty I have is that each TotInterest is different, as is each TotEquity. I am unsure where to even begin.

http://www.funkylogic.co.uk/equity.pdf
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Have you seen this eseminar? It explains all.

https://admin.adobe.acrobat.com/_a200985228/p87746471/

You might also want to read this article, it'll help to put the whole LC scripting thing in to perspective.
http://www.pdfscripting.com/public/department52.cfm

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RusticRanger
Registered: Jun 14 2010
Posts: 27
Unfortunately I cannot post code (yet) until I get to 10 posts
RusticRanger
Registered: Jun 14 2010
Posts: 27
I followed the seminar, and have conformed all of the structuring - I then tried to use the sample scripting found in the WJOrderForm
RusticRanger
Registered: Jun 14 2010
Posts: 27
the scripting for my particular problem still eludes me. All I get on each addInstance page is the first value - I want it to keep a running total. I have posted the particular page that this problem occurs -
link sent before.
RusticRanger
Registered: Jun 14 2010
Posts: 27
 var flds1 =xfa.form.topmostSubform.resolveNodes("$form..s2_2_6[*].TotEquity"); var flds2 =xfa.form.topmostSubform.resolveNodes("$form..s2_2_6[*].TotInterest");   var sum = 0; for(var i=0;i<flds1.length;i++) for(var i=0;i<flds2.length;i++) { if(!isNaN(flds1.item(i).rawValue)) sum += flds1.item(i).rawValue * flds2.item(i).rawValue/100; } sum;

All I get on each addInstance page is the first value - I want it to keep a
running total. I have posted the particular page that this problem occurs -
link sent before.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You have repeated variable for the index in the first loop in the second loop, a violation of the 'scope' of the variable. You should pick a different variable name for that index or the scripting language will recast it and modify it with each iteration of the loop.

Also try manually walking through the script. It appears you are going to add all of the total interest fields with each addition of an equity field. Commenting what you script is doing may also help others understand what you are trying to do.

You need to carefully read the introductory page for the scripting references. They should explain the concept of 'scope' for variables.

George Kaiser

RusticRanger
Registered: Jun 14 2010
Posts: 27
I am sorry, but I am too new to this to understand. The file in question is at
http://www.funkylogic.co.uk/equity.pdf

In a nutshell what I want to achieve is this: a cleint may own several properties, and have different percentage holding on each. Each property has a separate page of questions. The first part of the equation is to calculate up the total equity in the property (TotEquity), and then based on the percentage holding (TotInterest), work out the individuals equity share (TotalB). The form has the option to tell us about another property (addInstance), and we then have a second page with its own TotalB. This TotalB then becomes a running total of all pages added.

I cannot find the specific scope reference you mention - do you have a link?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I'm pretty sure you only need one loop. The intest and equity are fields on the same line, correct? Just delete the first "for" statement.

Now, if it's still now working you'll need to do some debug.

There is another route you could take with this. I understand that over at the Adobe forums that technical support is actually fixing peoples forms. You could try there:
http://forums.adobe.com/community/livecycle/livecycle_es/livecycle_designer_es


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
RusticRanger wrote:
I am sorry, but I am too new to this to understand. The file in question is at
http://www.funkylogic.co.uk/equity.pdf

In a nutshell what I want to achieve is this: a client may own several properties, and have different percentage holding on each. Each property has a separate page of questions. The first part of the equation is to calculate up the total equity in the property (TotEquity), and then based on the percentage holding (TotInterest), work out the individuals equity share (TotalB). The form has the option to tell us about another property (addInstance), and we then have a second page with its own TotalB. This TotalB then becomes a running total of all pages added.

I cannot find the specific scope reference you mention - do you have a link?
You have a variable that is a counter for a loop, and you are modifying it within the loop. Do you think this is confusing? Well it is for any programming language. So you should not do it. If you need a second counter, create a new differently named variable.

George Kaiser

RusticRanger
Registered: Jun 14 2010
Posts: 27
Hi - found the solution which is:

var vProperties = _Page1.count;
this.rawValue = 0;
for (var i=0; i
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahh, so the issue with the previous script was that the wrong repeated subform was used in the "resolveNodes" function. You could have used the same script as before useing this node list.

var oFormNodes = xfa.resolveNodes("$..Page1[*].s2_2_6");

In LiveCycle scripting the form hierarchy is everything.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RusticRanger
Registered: Jun 14 2010
Posts: 27
So I am fast learning... again, though, thanks for the pointers. I will learn eventually.
LeeRain
Registered: Jul 7 2010
Posts: 3
I cannot find the specific scope reference you mention - do you have a link?
__________________
[url=http://www.onlinedatingportfolio.com/]Online Dating Reviews[/url]
[url=http://www.myhealthysexlife.com/category/health-articles/]Healthy sex[/url]

Lee Rain

PurpleHope
Registered: Jul 28 2011
Posts: 2
I use the XML Editor all the time and problems like those never occur. That's why I am so satisfied with this kind of editor. I prefer using it than other programs that I don't really understand.