Error: SyntaxError: Unexpected identifier

Hi, I am trying out the scripting side of Seatable and I am having trouble with my code. This is what I have got, but it keeps telling me I have an “error: SyntaxError: Unexpected identifier”

var date = new Date();
const pasteTable = ‘Paste’;
const pasteColumnName = ‘Name’;
const pasteColumnName1 = ‘Date’;
const copyTableName = ‘Copy’;
const copyViewName = ‘Default View’;
const copyColumnName = ‘Your name?’;
const copyColumnName1 = ‘Date’;
const winningCount = 5;
const table = base.getTableByName(copyTableName);
const view = base.getViewByName(table, copyViewName);
const rows = base.getRows(table, view);
const winningTable = base.getTableByName(pasteTable);

for (let i = 0; i < rows.length; i++) {
let index = i
selectedRow = rows[index]
if copyColumnName1 = base.utils.formatDate(date){
const selectedName = selectedRow[copyColumnName]
const selectedDate = selectedRow[copyColumnName1]
base.addRow(winningTable, {[pasteColumnName]: selectedName, [pasteColumnName1]: selectedDate});
}
};

I am not a programmer so appreciate I might the above completely wrong, but I am willing/ trying to learn. What I am trying to do is for the script to look at each row and if the date in the date column matches todays date then it copies some of the information from that row and puts in another table. Anybody have any advice or tips on what I am doing wrong?

You can use this script:

var date = new Date();
const pasteTable = 'Paste';
const pasteColumnName = 'Name';
const pasteColumnName1 = 'Date';
const copyTableName = 'Copy';
const copyViewName = 'Default View';
const copyColumnName = 'Your name?';
const copyColumnName1 = 'Date';

const table = base.getTableByName(copyTableName);
const view = base.getViewByName(table, copyViewName);
const rows = base.getRows(table, view);
const winningTable = base.getTableByName(pasteTable);

let today = base.utils.formatDate(date);
output.text(today);

for (let i = 0; i < rows.length; i++) {
    selectedRow = rows[i];
    let dateInRow = selectedRow[copyColumnName1];
    if (dateInRow == today) {
        const selectedName = selectedRow[copyColumnName];
        const selectedDate = selectedRow[copyColumnName1];
        base.addRow(winningTable, {[pasteColumnName]: selectedName, [pasteColumnName1]: selectedDate});
    }
};

Thanks @daniel.pan

That worked exactly how I wanted it. I really am liking how Seatable functions and will fit the purpose for what I am trying to do.

@daniel.pan, I presume you can’t use…

base.addRow(outputTable, {[pasteColumnName]: selectedName, [pasteColumnDate]: selectedDate});

…to add to a linked column?

I’m sorry modify linked column via JS scripts is not supported yet. It will be added in a later version.

Thanks Daniel,

With my java script, how do I make it paste to a linked field? const pasteColumnName = 'Name'; is referring to a linked field.

This can be used only for copying between tables in a single base?

What if you have 2 bases and you want to copy between them?

Operating on link field is not supported yet. I will let you know once the feature is added.

You will need to use Python script instead.