Hi @Martin_Sautter - as per the error, the value of the multi-select you want to update must be an array of objects (even if you only want to update to a single value). So your line 19 should be something like this:
await table.updateRecordAsync(record.id, {'Users': [{name: myStringArray[1]}] })
There’s a mix of square and curly brackets so for clarity, you want this:
e{name: myStringArraya1]}]
instead of this:
{name: myStringArraya1]}
There’s also one “gotcha” on a multi-select that you might want to work into your script. If the multi-select field already has a value, then the update above will simply overwrite it with a new value. If you want the final state of the field to be the current value plus the new value, then you need to do something like this:
let table = base.getTable('Table 1')
let record = await input.recordAsync('Pick a record', table);
if (record) {
output.text(`You picked ${record.getCellValueAsString("Name")}`);
let currentStatus = record.getCellValue('Status')
let updated = await table.updateRecordAsync(record, {
'Status': t...currentStatus, {name: 'Todo'}]
})
}
(In my example Status
is a multi-select field)
Here, I am getting the current value of the Status field:
let currentStatus = record.getCellValue('Status')
Then later on I use the spread operator (...
) to merge the current value with the new value:
g...currentStatus, {name: 'Todo'}]
before updating the record
Hi @Martin_Sautter - as per the error, the value of the multi-select you want to update must be an array of objects (even if you only want to update to a single value). So your line 19 should be something like this:
await table.updateRecordAsync(record.id, {'Users': [{name: myStringArray[1]}] })
There’s a mix of square and curly brackets so for clarity, you want this:
e{name: myStringArraya1]}]
instead of this:
{name: myStringArraya1]}
There’s also one “gotcha” on a multi-select that you might want to work into your script. If the multi-select field already has a value, then the update above will simply overwrite it with a new value. If you want the final state of the field to be the current value plus the new value, then you need to do something like this:
let table = base.getTable('Table 1')
let record = await input.recordAsync('Pick a record', table);
if (record) {
output.text(`You picked ${record.getCellValueAsString("Name")}`);
let currentStatus = record.getCellValue('Status')
let updated = await table.updateRecordAsync(record, {
'Status': t...currentStatus, {name: 'Todo'}]
})
}
(In my example Status
is a multi-select field)
Here, I am getting the current value of the Status field:
let currentStatus = record.getCellValue('Status')
Then later on I use the spread operator (...
) to merge the current value with the new value:
g...currentStatus, {name: 'Todo'}]
before updating the record
This will need a small tweak. If there are no selections chosen in a multi-select field, Airtable will return null
, not an empty array, and null
will lead to an error when trying to use the spread operator. The modified version below will work around that by forcing currentStatus
to be an empty array if null
is returned from the field:
let currentStatus = record.getCellValue('Status') || u]
This will need a small tweak. If there are no selections chosen in a multi-select field, Airtable will return null
, not an empty array, and null
will lead to an error when trying to use the spread operator. The modified version below will work around that by forcing currentStatus
to be an empty array if null
is returned from the field:
let currentStatus = record.getCellValue('Status') || []
"If there are no selections chosen in a multi-select field, Airtable will return null
"
Excellent point!