[Help Request] I'd like to compare two tables and create a new table in the process

Hello,

I am really new to scripting and I tried to run a script that compares two tables. The tables are not very different and use the same data formats (strings and integers). The head row of the two tables is identical. So for example table 1: Student, StudentID… table 2: Student, StudentID… So in the same base only the content under the head row varies a bit and is sometimes also identical. Now I need to check every column and row. If everything matches, there is no need for action. If something changes I need a new table that contains the changes. I hope that makes sense. I tried with examples I found in the web:

  const altTableName = 'ALT';
  const alternativeViewName = 'Default View';
  const table = base.getTableByName(altTableName);
  const view = base.getViewByName(table, alternativeViewName);
  const neuTableName = 'NEU';
  const table2 = base.getTableByName(neuTableName);
  const view2 = base.getViewByName(table2, alternativeViewName);
  const winningTable = 'Vergleich_Tagesauszug'
  const table3 = base.getTableByName(winningTable);
  const rows = base.getRows(table, view)
  const columns = base.getShownColumns(table, view);

function RowExists(table, view, columnName, columnValue)
{
var hasColumnOrChange = new Array(2);
hasColumnOrChange[0] = false;
hasColumnOrChange[1] = true;
//const rows = base.getRows(table, view)
//const columns = base.getShownColumns(table, view);
columns.forEach((column)=>
{
if(column.name == columnName)
{
hasColumnOrChange[0] = true;
}
})
if(hasColumnOrChange[0])
{
rows.forEach(row=>
{
if(row[columnName] === columnValue)
{hasColumnOrChange[1] = false;
}
});
}
return hasColumnOrChange;
}
for (var i = 0; i < rows; i++)
{
for (var j = meinArray[i].length; j < columns; j++)
{
meinArray[i].push(0);

const rows2 = base.getRows(table3, view);
const selectedColumnName = ‘Name’;
const selectedRows = meinArray[0], updatedRows = rows2[0];

rows2.forEach((row) => {
if (row[columnName] === ‘name’) {
selectedRows.push(row);
updatedRows.push({columnName: ‘name1’});
}
});
base.modifyRow(table3, selectedRows, updatedRows);
}
}

This may have many issues, but I don’t know how I may get it to work. It at least doesn’t show me that something is wrong. It just doesn’t do anything.

Help would be much appriciated.

Sincerly,
Max

Hi, welcome to the SeaTable forum. Did you get to solve the problem in between? It seems no one on this forum could help you with the JavaScript. I’m sorry!

However, it seems to me that perhaps the SeaTable Scripts Programming Manual could be helpful!