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

Add a table row to a different table based on information from existing table

realname
Registered: Aug 15 2008
Posts: 93

I have a form with two tables. One field in the second table is acquired from a row in the first table. When a row is dynamically added using addinstance in the first table, a corresponding row is added to the second table.
 
My problem is that the added row in the second table, does not acquire the data from the newly added row in the first table, rather it is still accessing the original row. How can I get it so that the newly added rows have the same information? In addition, if a row is deleted in the first table, the corresponding row needs to be deleted in the second table. Is this possible?
 
Thanks!

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, this is all possible. But it's a slightly complex management problem. The first bit is to be able to correctly associate a line in the first table with a line in the second. Do you have a method to do this? Are they in the same order? same number of lines? Is there a shared piece of unique data, such as an ID?

Lines in a table can be easily acquired using the "resolveNode" function. Are you familiar with this function?

How is data copied from one table to the other? in a calculation event?

How are lines deleted? is there a delete button on each line in the first table?

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

realname
Registered: Aug 15 2008
Posts: 93
The second table is retrieving the data in the first table using form-calc and the calculate method, basically just $=main.expdetailssub.exptable.details.transportSubTotal. They are not in the same order as not all of the row information in the first table is required in the second table but each item has a unique name in both tables.

There will be the same number of rows as adding a new row in the first table adds it to both and deleting a row I have so far, only set on each row in the first table using: _details.removeInstance(this.parent.index);

I am not overly familiar with the resolveNode function.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Watch this video:

http://adobechats.adobe.acrobat.com/p87746471/

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

realname
Registered: Aug 15 2008
Posts: 93
Well I'm back to this problem. I had to put it aside for a while to tackle some other projects higher on the priority list but this one has now made it back to the top.

I watched the mentioned video and have done some additional searching for information on resolveNode and think I have a better understanding of its function however, am still not sure how to do what I need.

I hope to better explain what I need. On page 1, I have a row named details. The user can add another detail row via an "add" button which will adds a corresponding row to a second table on page 2. This second table is populated with the data from the first table. So far, when a new row is added, the same row data is not adding in the second table. I tried using resolveNode here and included [i] after details in the referencing but this does not work.

In addition, each details row has a "delete" button. When pressed, it also needs to delete the corresponding row in the second table. After watching the video where referencing the this.parent.index, although well explained, I believe my form would be going in descending order down the heirarchy as the table on page 1 is controlling the information on the second table.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you assume that the repeated rows for both tables are added and deleted in sync. Then the row index number can be used to match rows in both locations.

When adding a row the "addInstance" function returns a reference to the newly created subform (Row). This can be used to initially copy values between the rows.

var oRowTable1 = _Deatails.addInstance();
var oRowTable2 = _OtherTableRow.addInstance();

oRowTable2.someField.rawValue = oRowTable1.someOtherField.rawValue;
...etc...

To delete rows in the second table, use the index from the first table.

// Delete Second Table Row
TopSubform.PageSubform.Table2._OtherTableRow.removeInstance(this.parent.index);
// Delete First Table Row, where this code is located in a delete button.
_Details.removeInstance(this.parent.index);




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

realname
Registered: Aug 15 2008
Posts: 93
Thank you. I now have the add table row in both tables working and the simultaneous delete row, however, in the add row, the second table is not picking up the new row data. This is what I used:

var oRowTable1=exptable._details.addInstance();
var oRowTable2=submissionForm._acctDetails.addInstance();

oRowTable2.acctDetails.Trans.rawValue = oRowTable1.details.transportSubTotal.rawValue;

I also tried using more explicit field referencing than what I have here and it is not working.

oRowTable2.Trans needs to equal the value in transportSubTotal

As it is right now, if the initial row value is $20, the second table also shows $20. When a new row is added with a value of $60, the second table has a new row but has the value of $20 again.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There is some detail missing. You'll need to do a little debug to figure it out. Add this code to the "Add" script.

console.println("SubTotal=" + RowTable1.details.transportSubTotal.rawValue);

This will display the subtotal value from table 1 at the time the row is added, in the Acrobat JavaScript Console.

How is the value in Table1 set in the first place?

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

realname
Registered: Aug 15 2008
Posts: 93
I've added this line but what exactly is it supposed to do as I don't see any change. The value in table 1 is the subtotal of 8 other fields in the same row using FormCalc.

The field in the second table is getting its value also with FormCalc with

$=form1.main.expdetailssub.exptable.details.transportSubTotal
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
To see what that line of code does you'll have to watch the video on the Console Window. There's a link in my signature block below.

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

realname
Registered: Aug 15 2008
Posts: 93
I've done that and this is the message:

var oRowTable1=exptable._details.addInstance();
var oRowTable2=form1.page2.submissionForm._acctDetails.addInstance();

oRowTable2.Trans.rawValue = oRowTable1.transportSubTotal.rawValue;
oRowTable2 is not defined
1:Console:Exec
ReferenceError: oRowTable2 is not defined
1:Console:Exec
undefined
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There's definately something wrong if "oRowTable2" is returning null. But rather than try and debug this, try a different solution.

Since the fields in Table 2 are getting data from table 1 through a calculation, there is another strategy. Force the calculations to execute.

Get rid of the code that uses "oRowTable2" and add this to the end of the script.

form1.page2.submissionForm.execCalculate();

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

realname
Registered: Aug 15 2008
Posts: 93
I actually did the console thing again because in my previous example I did not have the code console.println in rather the code rather I had copied and pasted the code in. This time, it is not Table 2 returning null it is in table 1:


oRowTable1.details is undefined
6:XFA:form1[0]:main[0]:expdetailssub[0]:exptable[0]:Row2[0]:Button1[0]:click
TypeError: oRowTable1.details is undefined
6:XFA:form1[0]:main[0]:expdetailssub[0]:exptable[0]:Row2[0]:Button1[0]:click

My script is this:
var oRowTable1=exptable._details.addInstance();
var oRowTable2=form1.page2.submissionForm._acctDetails.addInstance();

oRowTable2.Trans.rawValue = oRowTable1.transportSubTotal.rawValue;

console.println("SubTotal=" + oRowTable1.details.transportSubTotal.rawValue);
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The "oRowTable1" variable is fine. You've got a referencing error in the "console.println" statement. "oRowTable1" is the "details" subform, so "details" shouldn't be in the path.

Also, make sure all the names are correct. The names of fields and subforms must exactly match the names shown in the hierarchy window.

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

realname
Registered: Aug 15 2008
Posts: 93
After much trial and error, I finally figured out that once I wrapped the 2nd table in a subform, it worked just fine and the appropriate value would duplicate.

I have however, just discovered another small issue with adding a new row. I have a description drop box populated depending on the values of two other boxex, when a new row is added, it is clearing out the description from the previous row. Here is a portion of the code:

On the change event:
this.rawValue = null;
this.clearItems();
this.setItemState(0, true);

On the enter event:
if(DeptCode.rawValue == 712 && DetailsCode.rawValue == 7110)
{
var arrayItems = eval(aClaims7110.value);
for (var i=0; i< arrayItems.length; i++)
{
this.addItem(arrayItems[i]);
this.setItemState(0,1);
}}if(DeptCode.rawValue == 719 && DetailsCode.rawValue == 7110)
{
var arrayItems = eval(aStats7110.value);
for (var i=0; i< arrayItems.length; i++)
{
this.addItem(arrayItems[i]);
this.setItemState(0,1);
}}
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This is the change event for what? It looks like "this" is expected to refer to a list element of some kind. If true then this sets up an awkward series of events. A change on this list is causing the list elements to be reset, invalidating whatever the user just selected. This kind of change (removing and adding the list items) should be done from outside the list events. Also, the "setItemState" call should be placed outside the loop where the items are being added.

If this list items are set with a change in the "DeptCode" field then an event on this field should be driving the change in list items, not a change on the list itself.




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

realname
Registered: Aug 15 2008
Posts: 93
A dropdown description box is populated based on the department code and detail code. The detail code is dependent on the department. The arrays are stored in the from properties variables. Obviously I don't know that much about javascript and had looked at your example purchase order form but had some difficulty applying it. I ended up getting the arrays to change based on a previous dropbox selection to work from another post in the forum and had thought all was fine.

If you can point me to another form example which may help, I would be grateful and am grateful for all your assistance this far.
techie777
Registered: Apr 14 2011
Posts: 1
I have a similiar issue I am trying to resolve. I have a form with 5 drop down menus. Once i make a selection from each drop down I would like a button to add the data from the selection to an on going list of fields or text boxes below and then reset the drop list. For example I have a Drop down called Name, Department and HR,once i make my selections i click a button it adds it to a row of fields with these names as headers, clears the drop down so i can make another selection that will add to the list underneath the previous entry.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
When implementing a complex series of dependencies it is very important to plan it all out ahead of time. Do some testing to figure out how the little bits work that will needed to build the solution and draw out a diagram of the interactions so there is a clear picture of how it will work.

You've gone beyond the point where the form issues can be resolved on a forum, you need some training or professional help, someone who can focus on your form.

The issue posed by techie77 is a good example. The desired interaction is complex. An action triggers another action that then re-triggers the first action, potentially creating an infinite loop. A structure called a state machine is needed to manage this type of interaction in a well behaved manor. State machines are an advanced programming topic. To solve this type of issue requires a knowledgeable professional who can spend some time analyzing project details and thinking about a solution.

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