Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Try catch in Airtable automation scripts

Topic Labels: Automations
608 3
Showing results for 
Search instead for 
Did you mean: 

I have tried a try-catch approach that whenever an option is not found in a single-select field due to typographical errors it will try to find a suitable option from the list of options in a single-select field. I have tested this approach in a scripting app and it works. However, when I applied this to a scripting action in Airtable automation, the field did not accept the value even if works in the scripting app. I don’tqu
Here is the coding block in question:

salesChannel={name: "value"} 
                await table.updateRecordAsync(recordId, {
                    "Sales Channel": salesChannel
                console.log("Updated sales channel")
        } catch (error){
            let salesChannelName =\s/g, '').toLowerCase()
            let alternativeChannel = channelOptions.filter(channel => {
                let channelName =\s/g, '').toLowerCase()
                return channelName.includes(salesChannelName)
            salesChannel = null
            if (alternativeChannel.length > 0){
                salesChannel = {name:alternativeChannel[0]["name"]}
                await table.updateRecordAsync(recordId, {
                    "Sales Channel": salesChannel
                console.log("Updated sales channel")
            } catch(error){
                console.log("Cannot Updates Sales channel from the alternatives")
3 Replies 3

Hmm. What does the console.log output look like? I had a few hiccups modifying a script into an automation, but I don’t see the pitfalls here. (I was doing a fetch and also I had to use the ID of a field rather than the name.)

For the last try catch the salesChannel value looks like this:
{name: [channelName]}
The channel name is one of the options in the single select field. However, it also encountered an error so it cannot update. The error looks like this from what I’ve remembered:
{Error: "d"}

Hmm, I really don’t see why the code wouldn’t work. As a last-ditch attempt, I’d replace the field name of “Sales Channel” with its ID? But if that were the problem, the very first table.updateRecordAsync would have failed as well.