Bonsoir Nathalie !
I prepared an answer this afternoon, but I didn’t have time to post it, and now that I see your last message, I’m not so sure it fulfills your needs
I thought your question was to know if it’s possible to copy every data from one table to another, including the data in the link-type columns…
For that purpose, I wrote this JavaScript script:
const sourceTable = 'Table1';
const targetTable = 'Table2';
const table1 = base.getTableByName(sourceTable);
const view = base.getViewByName(table1, 'Default View');
const tables = base.getTables();
const columns1 = base.getColumns(table1);
cols1 = []
columns1.forEach((column) => {
if (column.type != "link-formula" && column.type != "formula") {
if (column.type=='link') {
cols1.push({'name': column.name, 'type': column.type, 'other_table': column.data.other_table_id});
}
else {
cols1.push({'name': column.name, 'type': column.type});
}
}
})
const table2 = base.getTableByName(targetTable);
// HERE you could eventually verify that every column present in your source table has its equivalent in your target table...
const row = base.context.currentRow;
output.text(row);
data={};
links=[];
cols1.forEach((col) => {
if (col.name in row && row[col.name]!=null){
if (col.type!="link") {
data[col.name]= row[col.name];
}
else {
let linkId = base.getColumnLinkId(targetTable, col.name);
let currLinks = [];
row[col.name].forEach((link) => {
currLinks.push(link.row_id);
})
links.push({'linkId': linkId, 'col':col.name,'ids':currLinks, 'other_table': col.other_table});
}
}
})
let newRow = base.appendRow(table2, data);
links.forEach((link) => {
let other_table_name="";
for (let i=0;i<tables.length;i++) {
if (tables[i]._id == link.other_table) {
other_table_name = tables[i].name;
break;
}
}
output.text('other table : '+other_table_name);
output.text(link.ids);
base.updateLinks(link.linkId, targetTable, other_table_name, newRow._id, link.ids);
})
Of course you’ll have to change the names of your source and target tables on the first two rows.
As I use base.context.currentRow
to get the current row, this script as to be launched on a specific line from a button.
To answer more specifically your last post, you can definitely imagine a script that gets directly the data from every rows, and even choose which columns you want to transfer. For now, my current script transfers data from every columns except from formulas and link-formulas columns, but it also considers that the target table already contains all the columns to transfer from the source table (there is no test for that, but it is also possible to check whether the columns exist or not, and even to create them when they don’t).
As far as I understand your problem, I’m not sure that buttons can help you that much as you talk about collecting all rows at once: buttons generally trigger an action (one of the proposed one or launching a script) for the current row. Personally, I use them only when I need a “row-specific” behaviour, otherwise I just create a script that I launch from the scripts panel.
Hope this helps,
Feel free to ask if you want some help about a specific script !
Bests,
Benjamin