


I have a form to collect data from a region on a quarterly basis. Data is collected in a dynamic table with the ability to report, by county, in expandable rows in the table. This functionality is working fine.
I want to dynamically create a second table (based on the first table). I have set up a button to dynamically creates an exact replica of the first quarter table for use in filling in second quarter data. I would like to ensure that when the second quarter table is created, the entries from table 1 are populated in the second table. I think I need to use some type of a counter and when creating the second table, use the counter to establish number of rows in the second quarter table. I also want to populate the county column so the user does not have to re-enter. I see code from a similar thread on how do that part, but do not know how to dynamically and correctly created the second quarter table. The table is wrapped in a subform. The add new quarter button code is simple javascript:
_UPT_Services.addInstance(1)
Screen shot:
Appreciate any help members can provide.
Views
Replies
Sign in to like this content
Total Likes
You could use the instance manager of the first table to see the count for how many instances (rows) there are.
Eg: Table1.instanceManager.count
You could then use switch or if to add rows based on the instance manager count in the button to add the second table. You would then prefill the second table based on the first.
Views
Replies
Sign in to like this content
Total Likes
I am a relatively novice in coding and have noticed you answer a lot of questions here. Any chance you could provide a bit of code on how to implement that?
Views
Replies
Sign in to like this content
Total Likes
Here is an example to help you understand instance referencing.
--------------------------------------------------------------------------------------
In my example i have a
Add Row Button - click event javascript
//add a row to table1
this.resolveNode('Table1._Row1').addInstance(1);
if (xfa.host.version < 😎 {
xfa.form.recalculate(1);
}
//with each click show the current instance in NumericField1
NumericField1.rawValue = Table1.Row1.instanceManager.count;
For the purposes of testing,
i added initialize code to the textfield in the table
this.rawValue = Table1.Row1.instanceManager.count; //when a new row is created, so is a textfield and it gets the value of the instance.
Duplicate Button - click event javascript
//show table2
//logic to determine the amount of instances (rows)
//logic to duplicate textfield contents into table2.
switch(NumericField1.rawValue)
{
case 2: //if NumericField1's value is 2, execute this code
Table2.presence = "visible"; //show the hidden table
this.resolveNode('Table2._Row1').addInstance(1); //add one row only because the table starts with 1 row initially
this.resolveNode("Table2.Row1[0].TextField1").rawValue = this.resolveNode("Table1.Row1[0].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row1 is instance 0 - [0]
this.resolveNode("Table2.Row1[1].TextField1").rawValue = this.resolveNode("Table1.Row1[1].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row2 is instance 1 - [1]
break;
case 3: //if NumericField1's value is 3, execute this code
Table2.presence = "visible"; //show the hidden table
this.resolveNode('Table2._Row1').addInstance(1);
this.resolveNode('Table2._Row1').addInstance(1);
this.resolveNode("Table2.Row1[0].TextField1").rawValue = this.resolveNode("Table1.Row1[0].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row1 is instance 0 - [0]
this.resolveNode("Table2.Row1[1].TextField1").rawValue = this.resolveNode("Table1.Row1[1].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row2 is instance 1 - [1]
this.resolveNode("Table2.Row1[2].TextField1").rawValue = this.resolveNode("Table1.Row1[2].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row3 is instance 2 - [2]
break;
case 4: //if NumericField1's value is 4, execute this code
Table2.presence = "visible"; //show the hidden table
this.resolveNode('Table2._Row1').addInstance(1);
this.resolveNode('Table2._Row1').addInstance(1);
this.resolveNode('Table2._Row1').addInstance(1);
this.resolveNode("Table2.Row1[0].TextField1").rawValue = this.resolveNode("Table1.Row1[0].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row1 is instance 0 - [0]
this.resolveNode("Table2.Row1[1].TextField1").rawValue = this.resolveNode("Table1.Row1[1].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row2 is instance 1 - [1]
this.resolveNode("Table2.Row1[2].TextField1").rawValue = this.resolveNode("Table1.Row1[2].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row3 is instance 2 - [2]
this.resolveNode("Table2.Row1[3].TextField1").rawValue = this.resolveNode("Table1.Row1[3].TextField1").rawValue; //give the textfield in table2 the same as the value in table1. Row4 is instance 3 - [3]
break;
default: //if NumericField1's value is not any of the previously specified cases, execute this code
//enter code to execute if the logic above is not matched.
break;
}
Notes:
Clicking Duplicate does nothing as the Instance Count numeric field does not meet the switch logic.
I added 3 rows in table1, then clicked Duplicate. Table2 is shown, two more rows are added, text from table1 is duplicated to the correct rows in table2.
This is by no means bulletproof code, there probably are other logic considerations, but it should give you a good start with referencing instances.
Views
Replies
Sign in to like this content
Total Likes