Created
May 26, 2021 23:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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