Skip to main content

I have a script that’s currently working to create one record on my Project/Yarn junction table, but I need it to create multiple records, one per linked cell value in Yarn (from stash), if there are multiple of these. I’ve had a looked on the forums but am struggling to find the solution, can anyone help? This is my current script:


let table = base.getTable(“Projects”);

let record = await input.recordAsync(‘Select a record to use’, table);

let populateTable = base.getTable(‘Project/Yarn’);

if (record) {

await populateTable.createRecordAsync({

“Project”: r{id: record.id}],

“Yarn used”: record.getCellValue(‘Yarn (from stash)’),

})

output.text(Record created: ${record.name})

} else {

output.text(‘No record was selected’);

}

Solved it:


// Change this name to use a different table

let table = base.getTable(“Projects”);

// Prompt the user to pick a record

// If this script is run from a button field, this will use the button’s record instead.

let record = await input.recordAsync(‘Select a record to use’, table);

let populateTable = base.getTable(‘Project/Yarn’);

let linkedRecordCellValue = record.getCellValue(‘Yarn (from stash)’);

for (let yarn of linkedRecordCellValue) {

// The below creates a record on the Project/Yarn table and populates

// the Project and Yarn fields with the data from the Project record

await populateTable.createRecordAsync({

“Project”: <{id: record.id}],

“Yarn used”: r{id: yarn.id}],

})

output.text(Records created: ${record.name}, ${yarn.name})

}


Reply