(scripting) IF statement within an IF statement not working

Hi All,

I am struggling with my scripting code and it looks ok but it doesn’t run. I cant work out what is wrong.

I am trying to get it to compare the name in one table with the name in a second table. It it finds the name in the second table then it does nothing but if it cannot find the name in the second table then it adds in the name from the first table.

Any help would be appreciated.

var date = new Date();
let today = base.utils.formatDate(date);
output.text(today);
const copyTableName = 'Companies';
const copyViewName = 'Default View';
const copyColumnName = 'Name';
const pasteTable = 'Jobs';
const pasteViewName = 'Default View';
const pasteColumnName = 'Name';

const table = base.getTableByName(copyTableName);
const view = base.getViewByName(table, copyViewName);
const rows = base.getRows(table, view);
const outputTable = base.getTableByName(pasteTable);
const outputView = base.getViewByName(outputTable, pasteViewName);
const outputRows = base.getRows(outputTable, outputView);

for (let i = 0; i < rows.length; i++) {  
    for (let a = 0; a < outputRows.lenght; a++) {
    selectedRow = rows[i];
    selectedRow1 = outputRows[a];
        let nameInRow = selectedRow[copyColumnName];
        let nameInRow1 = selectedRow1[pasteColumnName];
            if (nameInRow != nameInRow1) {
                output.text("worked");
                    const selectedName = selectedRow[copyColumnName];    
                    base.addRow(outputTable, {[pasteColumnName]: selectedName});
   }
  }
 };
output.text(today);
output.text("end");

Anyone who can answer this will get a “Like”!

@daniel.pan are you able to help on this. it works perfectly if the IF statement is not nested like the below:

for (let i = 0; i < rows.length; i++) {  
    selectedRow = rows[i];
        let nameInRow = selectedRow[copyColumnName];
            if (nameInRow != "Jack") {
                output.text("worked");
                    const selectedName = selectedRow[copyColumnName];    
                    base.addRow(outputTable, {[pasteColumnName]: selectedName});
  }
 };

Is it just that you cant nest the IF statement in Seatable or have I got something wrong in my code? I did think that maybe the second “for” statement might not like me using the letter “a” for holding the value.

I have solved now. I needed to remove “{” and “}” that was attached to the second “for” statement.

But now it opens up another issue. My second “for” statement only counts the first record. Therefore the line “outputRows.lenght” is zero even though I have about 13 other records in there.

How do I get the below to recognise that my table has more then one row?
for (let a = 0; a < outputRows.lenght; a++)