Help

Re: Create multiple records based on linked cell values

Solved
Jump to Solution
862 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Nicole_Hawkesf1
6 - Interface Innovator
6 - Interface Innovator

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”: [{id: record.id}],
“Yarn used”: record.getCellValue(‘Yarn (from stash)’),
})
output.text(Record created: ${record.name})
} else {
output.text(‘No record was selected’);
}

1 Solution

Accepted Solutions
Nicole_Hawkesf1
6 - Interface Innovator
6 - Interface Innovator

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”: [{id: yarn.id}],
})
output.text(Records created: ${record.name}, ${yarn.name})
}

See Solution in Thread

1 Reply 1
Nicole_Hawkesf1
6 - Interface Innovator
6 - Interface Innovator

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”: [{id: yarn.id}],
})
output.text(Records created: ${record.name}, ${yarn.name})
}