Feb 20, 2023 03:15 PM - edited Feb 20, 2023 03:15 PM
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!
Solved! Go to Solution.
Feb 20, 2023 06:03 PM
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);
}
Feb 20, 2023 06:03 PM
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);
}
Feb 21, 2023 07:44 AM
Perfect! Thanks. Clear and simple.