Help

Re: Try catch in Airtable automation scripts

1627 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Carmel94
5 - Automation Enthusiast
5 - Automation Enthusiast

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"} 
try{
            if(salesChannel){
                await table.updateRecordAsync(recordId, {
                    "Sales Channel": salesChannel
                });
                console.log("Updated sales channel")
            }
        } catch (error){
            console.log(channelOptions)
            let salesChannelName = salesChannel.name.replace(/\s/g, '').toLowerCase()
            console.log(salesChannelName)
            let alternativeChannel = channelOptions.filter(channel => {
                let channelName = channel.name.replace(/\s/g, '').toLowerCase()
                return channelName.includes(salesChannelName)
            })
            salesChannel = null
            if (alternativeChannel.length > 0){
                salesChannel = {name:alternativeChannel[0]["name"]}
            }
            console.log(salesChannel)
            console.log(recordId)
            try{
                await table.updateRecordAsync(recordId, {
                    "Sales Channel": salesChannel
                });
                console.log("Updated sales channel")
            } catch(error){
                console.log(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.