Skip to content

Instantly share code, notes, and snippets.

@on2air
Created May 26, 2021 23:43
Show Gist options
  • Save on2air/c1f296fa811817a655cc9920d640242e to your computer and use it in GitHub Desktop.
Save on2air/c1f296fa811817a655cc9920d640242e to your computer and use it in GitHub Desktop.
Airtable script to perform either an update or create depending on a match found
const {id,name} = input.config()
//get table from base
const tblPipeline = base.getTable("📚 Content pipeline")
//get records from table
const pipelineRecordsQuery = await tblPipeline.selectRecordsAsync()
const pipelineRecords = pipelineRecordsQuery.records
//find matching record based on matching id from input and source_id in table
let match = pipelineRecords.find( record => record.getCellValueAsString("Source ID") === id )
//if match, perform update
if(match){
await tblPipeline.updateRecordAsync(match.id, {
"Name" : name
})
}else{
await tblPipeline.createRecordAsync( {
Name: name,
"Source ID": id
})
}
//if no match, then create new record using name and id as the source_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment