Hello,
I'm trying to write a custom script (and I'm a JS novice) to extrtact/parse the data from a csv file that an external user would attach to a form submission. I need that data from the csv to then be uploaded into another airtable table within the same base. I tried setting this up with Make and Zapier and webhooks where the form is on Softr instead of Airtable directly but Make/Zapier couldn't read a file attachment on Softr only a urls like a Google Drive link.
Here is my starter code: I'm currently getting an error on my forEach(function). Any help is madly appreciated!!
//Set up variables
var sourceTableName = 'Form'; //name of table to extract data from
var targetTableName = 'Claim Assignments'; //name of table to upload data to
var csvAttachmentFieldName = 'attachments'; //name of attachment field containing CSV file
//Get source table
var sourceTable = base.getTable(sourceTableName);
//Get target table
var targetTable = base.getTable(targetTableName);
//Get records from source table
var sourceRecords = sourceTable.selectRecordsAsync();
//Loop through each record in source table
sourceRecords.forEach(function (record) {
//Get attached CSV file field from record
var csvFile = record.getCellValue(csvAttachmentFieldName);
//Extract text from CSV file
var text = extractCSVText(csvFile);
//Map text from csv onto columns in target table
var fields = {};
fields['Assigned Adjuster'] = text[0]; //map text from csv in first column to text field 1
fields['Policy Holders'] = text[1]; //map text from csv in second column to text field 2
//Create new record in target table
var newRecord = targetTable.createRecord(fields);
});
//Function to extract text from csv file
function extractCSVText(file) {
// code to extract text from csv file
}
getTableByName: any;