Hello, AirTable forum!
I am trying to figure out how to update an AirTable, using the Scripting extension and drawing from an external API (LegiScan). The issue I am running into is that first, I am incredibly new to JavaScript, and second, single- and multi-select options are causing me some trouble. I have reviewed a number of posts in this forum about APIs, as well as the "Cell values and field options" documentation (https://airtable.com/developers/scripting/api/cell_values) but I cannot figure a solution in this case--this is likely my newness to and lack of skills with JavaScript! (I previously mainly coded in R, which is...not the same.)
My code can pull the data (and reformat a date), but I cannot update any field that is single- or multi-select, and I am also struggling to declare multiple fields to update (this is, I think, just an issue tied in with the single- and multi-select).
As an example of my annotated code (my API token has been removed for privacy) that shows how I am trying to update the already-existing last updated single-select field of a particular bill in my AirTable:
// Setting up API
let apiToken = 'myAPItoken'
//Setting it to link to a particular table
let table = base.getTable('Test')
let { records } = await table.selectRecordsAsync()
// Setting up the call as a "for" loop
// For updating bill info
for (let record of records) {
let billUpdate = await remoteFetchAsync(`https://api.legiscan.com/?key=${apiToken}&op=getBill&id=${record.name}`)
// Has to be in json format for AirTable
let data = await billUpdate.json()
// Reformatting the date so it matches the format I want it to be
let status_date = new Date(data.bill.status_date)
let lastAction = (status_date.toLocaleDateString("en-US"))
// Updating a field/add to the table: Updating the last date of something happening
await table.updateRecordAsync(record, {
'Last Action': lastAction
})
}
The error message I am getting is:
ERROR
j: Can't set cell values: invalid cell value for field 'Last Action'.
Cell value has invalid format: <root> must be an object
Single select field value must be an object with at least one of 'id' or 'name' as a property.
at main on line 21
I have the feeling this is related to how I am updating the table, but I've spent a few days on this, and I just can't figure the solution. Thank you in advance for your help!