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

FormCalc Sum in a Table - LiveCycle 8.0

MarionSchweda
Registered: Jan 14 2008
Posts: 33
Answered

I have followed the help screen's "To perform calculations in a table".
I have a table in a positioned subform in a flowed form. I have a header row, 3 rows of numeric fields and a footer row for totals which are also numeric fields.
My script is in FormCalc and says:

sum(Table.Row[*].C1[*])

as per the example in the Help Screen.

My error message says:

"accessor 'Table.Row[*].C1[*]' is unknown."

What am I doing wrong?

I have used FormCalc sum in LiveCycle 7.0 successfully and have even tried copying those scripts across but have had no luck.

Thanks and regards, Marion

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You should total each column individually and then if needed sum the sum of the columns.

George Kaiser

MarionSchweda
Registered: Jan 14 2008
Posts: 33
I have a header row, 3 body rows and a footer row. I am only working on one column at the moment because there's no point going on until that one works.
My 3 Body Cells are all called C1 and my Total Cell in the Footer Row is called T1.

I have just tried sum(C1[*]). Doesn't work.

Initially, my Body Cells had different names. ie,

LC1
MC1
IC1

I tried:

sum(LC1[*], MC1[*], IC1[*])

which I had used successfully in an earlier version of the form designed in LiveCycle 7.0 and still works. I had made this table myself as the table tool didn't exist in 7.0.

As I'm upgrading to 8.0 - I thought I'd replace my home-made table with one created with the table tool as it would be neater and work better!

I always get the same error message: "accessor unknown".

I've checked the binding - that seems fine. I've put the "comb over" on and off.

I've just tried sum(C1, C1, C1) for the heck of it.

Same error message.

Any ideas?

Regards, Marion
obmet
Registered: Jan 26 2008
Posts: 9
Did you ever solve this one Marion?

John
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you studied the Purchase form template?

For the "Amount" column the sum is:

Sum(Amount[*])

Which is instructing FormCalc to take each "Amount" field and sum them up. Each amount field is an element an array called "Amount" and the individual elements are named "Amuount[0]" through "Amount[6]".

George Kaiser

MarionSchweda
Registered: Jan 14 2008
Posts: 33
Thanks gkaiseril, I understand but I can't get it to work. I have studied the Purchase Order form and I've made it myself while teaching myself forms. As I said, I have an earlier version of my form where I made the financial table myself and the formula works there just fine. It's got something to do with the Adobe 8.0 built-in table tool.
The help screen I followed is: Using LiveCycle Designer > Working with Form Designs > Using tables > Working with data in tables > To perform calculations in a table
It says "You can use the sum function in FormCalc to total the values in a column. You must add the calculation to the footer row of the table."

I followed the example given which is basically the same as my table. The example gives the formula:
sum (Table.Row[*].Q1[*])
I have formatted my last row as a footer row. Same error message.

I have tried variants of the normal FormCalc sum formulas, like the one you've suggested. That is:

sum(Amount[*])

I've changed cell names, I've turned caps on and off, put spaces in and out, reformatted my row as a body row, etc. Same error message.

And the error message is:

Script failed (language is formcalc; context is xfa[0].form[0].RootSubformFlowed[0].#subform[15].Table1[0].Row4[0].TC1[0]
script=sum(Table.Row[*].C1[*])
Error: accessor 'Table.Row[*].C1[*]' is unknown.

Sometimes #subform[15] is replaced with FinTableSubformPosition[0] in the error message.

Could it have something to do with the fact that the table subform is positioned whereas the form as a whole is flowed?

Anyway, I'm going back to the table I used before as it works and I can't wait for a solution although I will continue to watch the forum with interest. If anybody comes up with an answer, I'll swap back to the table as it does look better.

Thanks, Marion
sconforms
Expert
Registered: Jul 10 2007
Posts: 92
Marion,

I'm sorry to see that this issue has caused you so much frustration!

I'm glad you pointed-out the help sample you were using to do this and I think I've found the place where you're going wrong:

In the sample table in the "Using LiveCycle Designer > Working with Form Designs > Using tables > Working with data in tables > To perform calculations in a table" help topic it does, in fact, say that you can calculate the sum of the Q1 fields in the Q1 column of the table by using the following FormCalc expression:sum(Table.Row[*].Q1[*])

What's important to realize, however, is that this expression is still *very specific* to the sample table itself. If you look closely at the image of the Hierarchy palette (in the same help topic) which describes the structure of the table, it contains a header row, two body rows (the ones being summed) and a footer row (which contains the "total" fields for the Q1, Q2 and Q3 columns). The important detail here is that *all body rows have the same name*: "Row".

Since all body rows have the same name, it's therefore possible to write the sum expression as follows: sum(Table.Row[*].Q1[*]) which means to sum the values of all Q1 fields found within all instances of the object "Row".

Now based on the error message you quoted in your last post,

Marion wrote:
Script failed (language is formcalc; context is xfa[0].form[0].RootSubformFlowed[0].#subform[15].Table1[0].Row4[0].TC1[0]
script=sum(Table.Row[*].C1[*])
Error: accessor 'Table.Row[*].C1[*]' is unknown.
I suspect that the rows in your table all have different names such as "Row1", "Row2", "Row3", "Row4", etc. If that's the case, attempting to use

sum(Table.Row[*].Q1[*])

to do the summation will produce an error because there's no object named "Row" in your table. Furthermore, the name of your table appears to be "Table1", not "Table".

So, if I'm correct about how your table and rows are named, you would need an expression similar to this one to do the summation:

sum(Table1.Row1.Q1, Table1.Row2.Q1, Table1.Row3.Q1)

Of course, if you have a lot of rows, that's gets a little tedious. That's why you should _rename_ your row objects to "Row" or "TableRow" (basically, give them all the same name). Once you do that, you can use the power of multiple instances to your advantage in order to calculate the sums. For example,

sum(Table1.TableRow[*].Q1[*])

(note I updated the expression to use "Table1" as the table object name and "TableRow" as the table row object name).

Stefan Cameron obtained his bachelor's degree with Honors in Computer Science at the University of Ottawa and is a Computer Scientist working on Adobe's LiveCycle server products, in particular on LiveCycle Designer ES for the past 5 years.

MarionSchweda
Registered: Jan 14 2008
Posts: 33
THANK YOU SO MUCH!!!
That worked.
To summarise what I did for everybody who might be reading this.
I have a table with a header row, 3 body rows and a footer row for the totals of each column.

Column 1 is C1
Column 2 is O1
Column 3 is RD1

Column 4 is the total of each row.

In the hierarchy pallette, I changed the Table name to Table.
I changed each Row name to just "Row", ie, not Row 1, Row 2 etc.
The heirarchy pallette then shows Row[0], Row[1], etc, which is fine.

To total column 1 in the table, I did:

sum(Table.Row[*].C1[*])

To total the rows:

sum(C1 + O1 + RD1)

For the grand total:

sum(TC1 + TO1 + TRD1)

where TC1, TO1 and TRD1 are the totals for columns 1, 2 and 3.

Right! Now that I've got that sorted, I'm going to copy the whole lot 5 times as I need a table covering 5 years.

And to do this, I'm going to select the rows I want to copy and use Edit > Duplicate, which is easier and neater than copy and paste.Good luck!
xrum
Registered: Feb 25 2009
Posts: 124
i keep getting "sum is not defined" error. I thought it was a built in function. what am i doing wrong?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
And what is the script you are trying to have LiveCycle Designer run?

This is a function call and not a variable or field name.

What is the scripting language you are trying to use?

LiveCycle Designer can use either FormCalc or JavaScript. 'Sum' is a FormCalc funciton and not a JavaScript function. If you set the language to 'JavaScirpt' you will get a message like:

Quote:
Sum is not defined
1:XFA:form1[0]:#subform[0]:Body[0]:Subtotal[0]:calculate
on Acrobat's JavaScript console.

Have you tried to run the sample of the Purchase Order or create a form using LiveCycle Designer's Purchase Order template?

George Kaiser

danielngct
Registered: Jan 12 2010
Posts: 3
have this message error came out... please help me... i try to do same way user has problem... but still can solve it...

script failed (language is formcalc; context is
xfa[0].form[0].form1[0].#subform[0].Table\.1[0].Rows3[1].T4[0])
script=sum(C1 + 01 + RD1)

Error: accessor 'C1' is unknown.
Script failed (language is formcalc; context is
xfa[0].form[0].form1[0].#subform[0].Table\.1[0].Rowa3[1].T4[0])
script=
sum(T1 + T2 + TT3)
Error:accessor 'T1' is unknown
danielngct
Registered: Jan 12 2010
Posts: 3
i mean still cannot solve this problem...
Raveeshkumar
Registered: Feb 15 2011
Posts: 1
Hi all,

When i execute the following script :


data.BP1.credit_t.credit_data::ready:form - (FormCalc, both)
var pltypn = $.credit_type.all.length
var plann
var bencnt
for i = 0 upto ( pltypn - 1 ) step 1 do
plann = $.credit_type[i].credit_detail.all.length
for j = 0 upto (plann - 1 ) step 1 do
// This code is to hide Stop Participation within period based on DEL_BPLAN Flag
if ( $record.PLAN_OFFER.DATA[0].CREDIT_PLANS.DATA[i].CREDIT_DETAIL.DATA[j].DEL_BPLAN == "X" ) then
$.credit_type[i].credit_detail[j].data.STOP_PERIOD.presence = "visible"
else
$.credit_type[i].credit_detail[j].data.STOP_PERIOD.presence = "hidden"
endif
endfor
endfor

I get an error.
It says " script failed Error: accessor '$.credit_type.all.length' is unknown.

Please help me on this.

Thanks in advance,
Raveeshkumar