Skip to main content

Export CSV with automation or script

  • February 6, 2021
  • 1 reply
  • 66 views

Hi, i’m looking for a script or automation of airtable to put my table into a csv file. How can i do it?
i found this. how can i download it?

// display app title
output.markdown('# Export to CSV');

// set the table name
let sourceTableName = "Search";

// identify the fields to be exported
let aFieldList = ["Name","Surname","Linkedin Link"];

// get the source data
let sourceTable = base.getTable(sourceTableName);

// get the data set for 2018/2019
let result = await sourceTable.selectRecordsAsync();

// set a counter for testing
let count = 0;

// iterate across all the records
let csvFile = "";
let csvRow  = "";
let csvItemCount = 0;
for (let record of result.records)
{
    // build the current csv row
    csvRow = "";
    for (var i in aFieldList)
    {
        csvRow += record.getCellValueAsString(aFieldList[i]) + ((i < aFieldList.length - 1) ? "," : "");
    }

    // add the row to the file
    csvFile += csvRow + "\r\n";
    csvItemCount += 1;

    // increment the row counter
    count += 1;

    // break if testing
    if (count > 100)
      break;
}
// display the contents of the csv file

output.inspect(csvFile);

1 reply

Brian_Sweeny
Forum|alt.badge.img+5
  • Participating Frequently
  • May 14, 2024

Hi Nasir!You probably figured this out already but I thought perhaps other might have the same question. Airtable provides an easy way to export to CSV. Check out the screenshot attached.

If you need more help with Airtable, feel free to schedule a session.