Skip to main content
Solved

Simple "Split Linked Data Cell into Separate Rows" Script

  • February 20, 2023
  • 2 replies
  • 55 views

Forum|alt.badge.img+6

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

IDLinked
1A,B
2B,C,D

And spit out the following table:

Table_2

IDEach_Link
1A
1B
2B
2C
2D

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); }

 

2 replies

TheTimeSavingCo
Forum|alt.badge.img+31

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); }

 


Forum|alt.badge.img+6
  • Author
  • Participating Frequently
  • February 21, 2023

Perfect! Thanks. Clear and simple.