Help

Re: How to copy a row with rating

2722 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Rajesh_Narayana
5 - Automation Enthusiast
5 - Automation Enthusiast

I am trying to duplicate a row from one table to another (using scripts). The table I am copying from has a column with “rating” type field in it.

How do I go about duplicating in the createRecordAsync script?

I tried something like

    let table1 = base.getTable("Table1");
    let table2 = base.getTable("Table2");
    let table1Rec = await table1.selectRecordsAsync();
    await table2.createRecordAsync({
      "Memo":[{icon: "star",max:table1Rec.getCellValue("Memo"),color:"yellow"}]
    }

I got an error. Summarizing it:

“(property) “Memo”?: 0 | 1 | 2 | 3 | 4 | 5
Type ‘{ icon: string; max: number; color: string; }’ is not assignable to type ‘0 | 1 | 2 | 3 | 4 | 5’.
Type ‘{ icon: string; max: number; color: string; }’ is not assignable to type ‘5’.(2322)”

14 Replies 14

Got it, thanks folks!

Is there a way to use a for loop to iterate through all of the fields instead of having to hardcode each one in?

Thank you!!
Paul Warren

I tried using your suggestion for 2 tables with identical rows and I’m getting this error on a multi-select column called ‘Genres’:

L: Can't create records: invalid cell value for field 'Genres'.
Could not find a choice with that ID or name

The code and tables are really simple:

let table = base.getTable("Source");
let query = await table.selectRecordsAsync();
let targetTable = base.getTable("Target");

for (let record of query.records) {
    await targetTable.createRecordAsync({
        "Book": record.getCellValue("Book"),
        "Genres": record.getCellValue("Genres"),
        "Cover": record.getCellValue("Cover"),
    });
}

Any ideas?

@TWu

Check out the answer in this thread.

You will need to adapt code slightly because you will need to map the arrray. But the idea is the same—the ids are different in the two tables, even though the option names are the same.

TWu
6 - Interface Innovator
6 - Interface Innovator

Thank you, that worked perfectly!