I'm a javascript developer, but all the examples I can come across are either too nuanced or specific for my needs, so I'm hoping to find a simple script to take the following table which has a column of linked records from a third table:
Table_1
ID
Linked
1
A,B
2
B,C,D
And spit out the following table:
Table_2
ID
Each_Link
1
A
1
B
2
B
2
C
2
D
Thanks!
Best answer by TheTimeSavingCo
Here's something that should do what you're looking for, and the code is below
let table = base.getTable('Table 1')
let record = await input.recordAsync('Pick a record', table);
let linkField = "Table 3"
let idField = "ID"
let tableToUpdate = base.getTable("Table 2")
let tableToUpdate_idField = "ID"
let tableToUpdate_eachLinkField = "Each_Link"
let linkedRecords = record.getCellValue(linkField)
let updates = new Array
for (let r of linkedRecords){
updates.push({
fields:{
[tableToUpdate_idField]: record.getCellValue(idField),
[tableToUpdate_eachLinkField]: r.name
}
})
}
while (updates.length > 0) {
await tableToUpdate.createRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
Here's something that should do what you're looking for, and the code is below
let table = base.getTable('Table 1')
let record = await input.recordAsync('Pick a record', table);
let linkField = "Table 3"
let idField = "ID"
let tableToUpdate = base.getTable("Table 2")
let tableToUpdate_idField = "ID"
let tableToUpdate_eachLinkField = "Each_Link"
let linkedRecords = record.getCellValue(linkField)
let updates = new Array
for (let r of linkedRecords){
updates.push({
fields:{
[tableToUpdate_idField]: record.getCellValue(idField),
[tableToUpdate_eachLinkField]: r.name
}
})
}
while (updates.length > 0) {
await tableToUpdate.createRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}