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

Dynamic table troubles

kerrykew
Registered: Nov 25 2008
Posts: 19
Answered

Good afternoon,
I've been trying to figure this out but haven't been able to, I'm hoping someone will come to my rescue.
 
I have a livecycle form that has two dynamic tables. The first table has a drop down box in the 5th column with two choices, "Controls are adequate" and "Controls are NOT adequate". If the users selects "Controls are NOT adequate" I would like the second table to add a new row and prefill the first column of that new row with the data entered into the first column of the first table. The second table is hidden until "Controls are NOT adequate" is chosen.
I tried the following in the change event of the first table's drop down box (column 5):
if (xfa.event.newText == "Controls are NOT adequate")
{
if(form1.FMAS102.presence == "hidden")
{
Form102.Table1.Row2.CorrProcessStep.rawValue = MainPag.Table1.Row2.ProcessStep.rawValue;
form1.FMAS102.presence = "visible";
}
else if(form1.Form102.presence == "visible")
{
form1.Form102.Table1.Row2.instanceManager.addInstance(1);
var cPStep = xfa.resolveNodes("form1.Form102.Table1.Row2.CorrProcessStep[*]");
for (var i=0; i <= cPStep.length-1; i++)
{
if(cPStep.item(i).rawValue == null)
{
xfa.resolveNode("form1.Form102.Table1.Row2.CorrProcessStep["+i+"]").rawValue = xfa.resolveNode("form1.MainPag.Table1.Row2.ProcessStep").rawValue;
}
}
}
}
 
The wierd thing is this code works as long as the user consecutively chooses "Controls are NOT adequate". The problem is when the user chooses the other choice for a couple of rows and then goes back to "Controls are NOT adequate" the new row is added but isn't prefilled.
Thanks in advance for any assistance you can provide.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Its all in the details. For example, the repeated row is "Row2", so the instance index used with the resolveNode function has to be applied to "Row2" in the SOM path, not to a field inside "Row2".

There's also another detail that might help you out. The addInstance() function returns a pointer to the newly created row, so there is no need find it with resolve node.

Now, in general I don't think you've completely thought out your process. Rows are only added to the second table when a specific option is selected from the first table. There is a direct relationship between a row in the first table and the created row in the second table. There are two issues here that have to be resolved. The first is how the relationship is made. How do you identify which row in the second table is related to which row in the first table? For example, if the user changes their mind and selects "Controls are Adequate", doesn't the associated row in Table 2 need to be deleted? The other issue is ordering. The user can choose options from any row in the first table. They are not limited to selecting them in order. So, then how are the rows in the second table ordered?

Before writing the code you need to walk though all the different usage scenarios and develop a consistent approach to handling the interaction.


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

kerrykew
Registered: Nov 25 2008
Posts: 19
Thank you so much for this valuable information! You are correct, I do need to think this through a bit more. I think the scenario where a user changes their mind is likely and must be addressed. Can you show me an example of how the addInstance pointer to the newly added object is used?
Again, thank you VERY MUCH for the assistance you have provided.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
When the new row in the second table is created some information in that row needs to be filled out. This is where you'd use the pointer.

var oNewRow = form1.Form102.Table1.Row2.instanceManager.addInstance();
oNewRow.orrProcessStep.rawValue = form1.MainPag.Table1.Row2.ProcessStep.rawValue;

Much simpler than the code in the post above. The resolveNode is unnecessary since data is being acquired from the first instance of the row in the First table.

For making a connection between the rows in the two tables you can put ID fields in both. Then use a for loop to search for the row with matching ID. This way you can sync of operations on both tables. You can also use a similar technique to insert a new row into the second table so that the rows in the second table appear in the same order as the corresponding rows in the first table.

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

kerrykew
Registered: Nov 25 2008
Posts: 19
Thanks!! Can you recommend a book or resource to expand my Livecycle scripting knowledge, right now I'm very limited as to what I can accomplish.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Sign up at www.pdfscripting.com

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