cancel
Showing results for 
Search instead for 
Did you mean: 

FormCalc Issue - help me figure out why this For Loop doesn't work

bryan_cain
Contributor
0 Kudos

//each occurance of sales order item number should give me total rows in the table
var total = Count(data.BodyPage.PageFlow.LineItems.Item.Row2[*].POSNR_VA) 

// this should give me the current sales order number
var firstSO = data.BodyPage.PageFlow.LineItems.Item.Row1.VBELN_VA.value.#text

//do once for each line in the table
for i = 0
	upto total 
		step 1 do
// get the value of the sales order number for the table row that matches the current loop pass		
		var secondSO = data.BodyPage.PageFlow.LineItems.Item.Row1<i>.VBELN_VA.value.#text
		var secondSOTotal = data.BodyPage.PageFlow.LineItems.Item.Row1<i>.BRGEW.value.#text
// if the two are equal, increment our subtotal 
			if (firstSO == secondSO) then
				$.value.#float = $.value.#float + secondSOTotal
			endif
endfor

This script is in a [subtotal line that is only shown at the end of each sales order|;. The math of the output is not working in a way that makes sense to me - it looks like this:

S01 | ITEM1 | 100

S01 | ITEM2 | 102

Subtotal | 204

S02 | ITEM1 | 103

S02 | ITEM2 | 104

Subtotal | 311

S03 | ITEM1 | 104

S03 | ITEM2 | 106

Subtotal | 316

S04 | ITEM1 | 107

Subtotal | 214

It should look like this:

S01 | ITEM1 | 100

S01 | ITEM2 | 102

Subtotal | 202

S02 | ITEM1 | 103

S02 | ITEM2 | 104

Subtotal | 207

S03 | ITEM1 | 104

S03 | ITEM2 | 106

Subtotal | 210

S04 | ITEM1 | 107

Subtotal | 107

So it seems there are 2 different issues here

1) It looks like it's skipping the first item in the table when doing the subtotal calculation

2) For each row where the subtotal line shows up, it's double counting

What am I doing wrong?

Thanks in advance, and let me know if I've been unclear.

Edited by: Bryan Cain on Feb 22, 2008 4:39 PM

Accepted Solutions (0)

Answers (2)

Answers (2)

bryan_cain
Contributor
0 Kudos

Solved the problem by rewriting in Javascript. If anyone is interested, you can see the solution here:

http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=12511

bryan_cain
Contributor
0 Kudos

Well, I fixed the double counting issue by changing the first line to

for i = 1

rather than 0. Now the only issue is the skipped first record. Anyone have any thoughts?

bryan_cain
Contributor
0 Kudos

Another update - I think I figured out why it's not working. However, I'm totally lost on how I'm going to fix it.

I think the problem is, when I try to access row number [0], which should be the first row in the table, it is accessing the current row. Consequently, the first row is not being accessed ever, and when I look at row [0], it double counts the current line.

I can think of a couple of hacks (like make sure that the first row the program passes the form is blank, hide blank lines, and start the loop from index 1 - but wow, that's ugly).

HELP! How do I access the first row of the table from another row in the table?

bryan_cain
Contributor
0 Kudos

Some more clarification that I posted on another forum. I'm going nuts here. Should I just give up and use a smartform?

I am passing delivery line items to the form. My form is structured like this:

LineItems

| HeaderRow

| Items (this is a grouping, and each occurance of the grouping maps to a record being passed to the form)

| | Row1 - VBELN_VA, BRGEW (sales order number and weight)

| | Row2 - POSNR_VA (sales order item)

| | Row3 - No Data worth mentioning here

| | FooterRow - SumGWeight (this field is the one that contains the script in my first post)

Two things that I should perhaps mention:

1) the footer row is not defined as a footer row in the Object/Row/Type field - it's defined as a body row and is part of the "Items" grouping, because I might need it to show up per line item.

2) there is a script in the FooterRow initialize event that hides the entire row if the current sales order number <> next sales order number in the table.

What I am trying to get to is a subtotal by sales order number. If I just write

Sum LineItems.Row1[*].BRGEW

as I understand it, I will get a total of all records. So, I came up with the code in my first post. Basically, what it should do is compare the current record with every other record in the table to see if the sales order number is the same. If it is, then we add that value to the current value.