Help

Simple "Split Linked Data Cell into Separate Rows" Script

Topic Labels: Automations
Solved
Jump to Solution
1441 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Aardvark
5 - Automation Enthusiast
5 - Automation Enthusiast

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!

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

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

 

See Solution in Thread

2 Replies 2
TheTimeSavingCo
18 - Pluto
18 - Pluto

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

 

Aardvark
5 - Automation Enthusiast
5 - Automation Enthusiast

Perfect! Thanks. Clear and simple.