Help

Airtable Script To Update A Field of Multiple Records After A Field In Another Table Is Updated

Topic Labels: Automations
Solved
Jump to Solution
607 1
cancel
Showing results for 
Search instead for 
Did you mean: 
reiedd
4 - Data Explorer
4 - Data Explorer

Context Unable to create an automation in Airtable. The path is as follows: An update in the "Sleep" field of Table1 triggers a search for records in Table2 that share a common field (using the "Name" field as the link). The automation then uses a script to update the corresponding records in Table2 with the updated "Sleep" content from Table1 into the Table2 fields, that have the same name, "NewSleep."

Automation Path Image Below:

My script is producing an error "'recordtoUpdate' is declared but its value is never read.(6133)." I believe what this means is the script doesn't understand or have a value it interprets from Table1 "Sleep" and therefore cannot update the the field of "NewSleep" for the records that have the corresponding name.

 
Script:
let records = input.config().records

let table1 = base.getTable("Table1");

let table2 = base.getTable("Table2")

let newsleep = table1.getField('Sleep')

for (let record of records) {

let recordtoUpdate = await table2.selectRecordAsync(record)

await table2.updateRecordAsync(record, {

'NewSleep': newsleep,

})

}
Script Image Below: 

 

1 Solution

Accepted Solutions
Sho
11 - Venus
11 - Venus

Check the value with "console.log(newsleep);".
getField()" cannot get the value of a record.
It is necessary to use "getCellValue()" to read the value.

Record - Airtable Scripting

See Solution in Thread

1 Reply 1
Sho
11 - Venus
11 - Venus

Check the value with "console.log(newsleep);".
getField()" cannot get the value of a record.
It is necessary to use "getCellValue()" to read the value.

Record - Airtable Scripting