Adding multiple items with varying quantities to check-in check-out base

I’ve connected a check-in check-out template to a Softr page and we can update inventory from either side, which is great. However I’m trying to add a new item which has a quantity of 24 however, when I jump over to Airtable there aren’t 24 individual records. Is there a way to configure the base so that when we add a new item with more than 1 quantity the base automatically creates a record for each individual item? Thank you!

This could be done with an Automation with a “Run a script” action:

  1. Set an automation to run when the {Quantity} field is greater than 1
  2. 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
  3. 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.

2 Likes

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.