Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Repeat data from one growable table into a new one

Avatar

Level 3

Hi there,

I've successfully managed to create a table in LC designer4 which grows - ie. it's a four column table with a header row followed by one row where I can add information into three table cells. If I need to have another row I click the add row button (placed within the header row) and a new one appears. There's also a remove button which can sytematically removed a row. I'll call this my parent table.

So far so good.

Maybe it's better to explain exactly what I'm doing here...

My parent table is a kind of to-do list Call it Table X. Each column is as such: 1. what needs to be done 2. who will do it 3. when will it be done

it's growable, so if there are more than one action that needs to be performed it will add extra rows.

I also want to create a new table which is an update on the to-do list Call it table Y:

column A. what needed to be done (this data is pulled directly from column 1 on the to-do list)  column B: did it happen? column C: if not, why not - columns B and C are new and are not pulling data from the to do list.

The problem is two fold: How do I repeat the data from column 1 (bearing in mind that I can't use global data binding as column 1 can have multiple different entries) and if I can get beyond that first hurdle, how do I make make table Y automaticall expand to the same amount of rows as table X?

I should mention that I'm a designer so my programming expertise is severely limited. I've managed to create the first table by looking at tutorials rather than knowing it myself. As far as I'm aware the first table is done in javascript.

Any help would be greatly appreciated!

1 Accepted Solution

Avatar

Correct answer by
Level 10

You need to loop through the tables and copy the data from the corresponding field.

You'll need to adjust the sample below to reference your table and field names.

Table1 = table to copy from

Table2 = table to copy to

Row1 = name of row that fields are in

ColumnA = the field name being copied

Here's the script (put it on the Click event of a button):

Table2._Row1.count = Table1._Row1.count;

var vCol1 = this.resolveNodes("Table1.Row1[*].ColumnA");

var vCol2 = this.resolveNodes("Table2.Row1[*].ColumnA");

for (var i = 0; i < vCol1.length; i ++) {

             vCol2.item(i).rawValue = vCol1.item(i).rawValue;

}

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

You need to loop through the tables and copy the data from the corresponding field.

You'll need to adjust the sample below to reference your table and field names.

Table1 = table to copy from

Table2 = table to copy to

Row1 = name of row that fields are in

ColumnA = the field name being copied

Here's the script (put it on the Click event of a button):

Table2._Row1.count = Table1._Row1.count;

var vCol1 = this.resolveNodes("Table1.Row1[*].ColumnA");

var vCol2 = this.resolveNodes("Table2.Row1[*].ColumnA");

for (var i = 0; i < vCol1.length; i ++) {

             vCol2.item(i).rawValue = vCol1.item(i).rawValue;

}

Avatar

Level 3

Hi Jono,

Sorry it's taken me so long to reply. Just tried your code and after a slight confusion (I neglected to place the button in the same subform), it works a treat.

Thank you so much - this is something that I couldn't have done on my own. I need to tweak a bit - I'd like the calculation to perform on open rather than on a button click, and I need to place the calculation within a different sub-form, but I'm going to try this myself first.

I owe you a pint and my gratutude. Thanks for your help.

Avatar

Level 6

I like Jono's solutuon but need it to be modified as such:

For a simple explanation, lets say Yes/No radio buttons are added to the rows in Table 1 to serve as determining factors whether or not to add that row to Table 2.  How would this script be modified? Also, please note that I will not be using an Add row button. The total row count in Table 1 will be known/ preset, however, Table 2 will have no rows to start.

So, instead of matching the same table count (apples to apples), the form would only populate Table 2 with copied info IF "Yes" is checked on that specific row.  In this case, Table 1 could have 10 rows to start, but Table 2 could have four (4), for example, if only 4 rows in Table 1 had "Yes" checked.

I guess one possible issue with this setup would be if someone later selected "No" on any particular row in Table 1...how would you know which row to delete in Table 2 if there is no "instance" or row count reference tied to teh Tables. I presume one possible solution is to require the user manually delete the row in Table 2 if it no longer applies.

NOTE: This all assumes new rows will be appended to the end of Table 2.

Please advise!

Thanks in advance