I’m running a scripting app that loops through all the records in my Airtable using await table.updateRecordAsync() in a few fields, including a single-select field. Every once in a while, through human error or something else, we’ll wind up passing something to the script that makes it try to update the single-select field with some value that isn’t one of the options for that field. Right now what that does is cause the script to throw an error and abort entirely. What I’d like to do is have it throw an error message and continue on to the next record in the table. What’s the best way to go about this?
Excerpt of the script in question below (for context, we’re a nonprofit helping folks in the criminal justice system):
if (parsedNewDate.valueOf() != parsedOldDate.valueOf() ||
postSentencePrison != newPrison||
inmate.releaseCode) {
if (parsedNewDate.valueOf() != parsedOldDate.valueOf()){ output.markdown(`*Updating release date of ${name} (or as BOP knows them, ${inmate.nameFirst} ${inmate.nameLast}) from ${projectedReleaseDate} to ${newDate}*`);
await table.updateRecordAsync(record, {
"Release Date": parsedNewDate,
});
};
if (inmate.releaseCode) { output.markdown(`Marking *${name} (or as BOP knows them, ${inmate.nameFirst} ${inmate.nameLast}) as released.*`);
await table.updateRecordAsync(record, {
"Status": { name: "Released"},
});
continue;
};
if (postSentencePrison != newPrison){ output.markdown(`*Updating location of ${name} (or as BOP knows them, ${inmate.nameFirst} ${inmate.nameLast}) from ${postSentencePrison} to ${newPrison}*`)
await table.updateRecordAsync(record, {
"Post-Sentence Prison": { name: newPrison},
});