Help

Script to update value from another table based on matching records

Topic Labels: Automations
957 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Faculty_Schedul
6 - Interface Innovator
6 - Interface Innovator

Hi, 

I am having issues with my script (screenshot attached)... can someone help me understand why it cannot find the record? My intent is to have a table record update every field that is a record in the in another table with the content field.

1 Reply 1
loyo
4 - Data Explorer
4 - Data Explorer

Try this:

// Get references to both tables
let table1 = base.getTable('Table 1');
let table2 = base.getTable('Table 2');

// Retrieve records from both tables
let table1Records = await table1.selectRecordsAsync();
let table2Records = await table2.selectRecordsAsync();

// Iterate over records in table 1
for (let record1 of table1Records.records) {
// For each record, iterate over records in table 2 to find a match
for (let record2 of table2Records.records) {
// Define your matching criteria here
if (record1.getCellValue('Matching Field') === record2.getCellValue('Matching Field')) {
// If a match is found, you can perform your desired operations
// For example, update a field in table 1 with a value from the matching record in table 2
await table1.updateRecordAsync(record1.id, {
'Field to Update': record2.getCellValue('Field from Table 2')
});
}
}
}