This could be done with an Automation with a “Run a script” action:
- Set an automation to run when the
{Quantity}
field is greater than 1
- Use a Run a Script action that has two input variables:
Name: quantity, Value: the trigger record's value for the quantity field
Name: recordID, Value: the trigger record's record ID
- Use the following script or something similar:
const inputConfig = input.config()
const table = base.getTable("Name of table")
const query = await table.selectRecordsAsync()
const record = query.getRecord(inputConfig.recordID)
const fieldValues = {
fields: Object.fromEntries(table.fields.filter(x => {
return !x.isComputed
}).map(x => {
const value = (!record.getCellValue(x)) ? null : (["singleSelect", "singleCollaborator"].includes(x.type) && record.getCellValue(x).id) || (["multipleSelects", "multipleCollaborators", "multipleRecordLinks"].includes(x.type) && record.getCellValue(x).map(y => {return {id: y.id}})) || record.getCellValue(x)
return [x.id, value]
}))
}
let quantity = Math.max(0, inputConfig.quantity - 1)
let recordValues = new Array(quantity).fill(fieldValues)
while (recordValues.length > 0) {
await table.createRecordsAsync(recordValues.slice(0, 50))
recordValues = recordValues.slice(50)
}
^ that will duplicate the record for however many times to equal the quantity minus 1. This will leave the original record how it is with Quantity still at 24 or whatever.