Skip to main content
Question

Export view in an automation

  • November 19, 2025
  • 6 replies
  • 26 views

Forum|alt.badge.img+13

Hi Guys,

 

Has anyone found a way to schedule an export of a view and send it as an email attachment as a csv natively in Airtable (possibly with a script)?

 

Thanks

6 replies

TheTimeSavingCo
Forum|alt.badge.img+31

Hm yeah, I think that’s doable and would need two automations.  The idea would be to:

  1. Automation 1:
    1. Construct the CSV text via a script
    2. Convert that text into base64
    3. Upload that as an attachment via the upload attachment endpoint
  2. Automation 2:
    1. Trigger after the attachment gets uploaded 
    2. Send it out

Lemme know if you hit any issues setting it up and I’ll see what I can do to help


Forum|alt.badge.img+13
  • Author
  • Inspiring
  • November 20, 2025

Thanks ​@TheTimeSavingCo.

I had a go yesterday at getting AI to write the script, but struggled to get Airtable to take a view as a variable. The below threw an error and ChatGPT later suggested the only way to do it was by listing all the fields and filters in the script itself (or as input variables). Would you agree or do you have any insights as to how I can get the script to reference the view directly?

 

// Read inputs
let { tableName, viewName } = input.config();

// Look up table + view
let table = base.getTable(tableName);
let view = table.getView(viewName);

// Get exactly the fields visible in this view
let exportFields = view.fields;

// Fetch records with only those fields (best practice)
let query = await view.selectRecordsAsync({
fields: exportFields
});

// Build CSV header
let csv = exportFields.map(f => `"${f.name}"`).join(",") + "\n";

// Build CSV body
for (let record of query.records) {
let row = exportFields.map(f => {
let val = record.getCellValueAsString(f) ?? "";
return `"${val.replace(/"/g, '""')}"`;
}).join(",");
csv += row + "\n";
}

// Output for the next automation step
output.set("csvContent", csv);

 

Many thanks!


Mike_AutomaticN
Forum|alt.badge.img+28

Hey ​@jwag,

This is what I’m using for getting views on my scripts:
 

let table = base.getTable("Table Name");
let view = table.getView("View Name");
let query = await view.selectRecordsAsync({fields: []});

 
Please feel free to reach out if you need any help setting this up!

Completely different matter, but would love to have you join our Airtable Hackathon! Make sure to sign up!!

Mike, Consultant @ Automatic Nation 
YouTube Channel


TheTimeSavingCo
Forum|alt.badge.img+31

The below threw an error and ChatGPT later suggested the only way to do it was by listing all the fields and filters in the script itself (or as input variables). Would you agree or do you have any insights as to how I can get the script to reference the view directly?

Ah, you’re already referencing the view in your script so that bit works fine.  To make things clearer, let’s split it into Records and Fields

Records wise, you’re good to go.  By referencing the view your filters come into play, and so you’re only going to export the records in that view

Fields is where it gets tricky; Airtable automations don’t have the ability to pull the visible fields from a view and so you’re going to have to list the fields manually I’m afraid.  To do that, you’d update ‘exportFields’ with your field names and update the mapping function to handle that change:

// Read inputs
let { tableName, viewName } = input.config();

// Look up table + view
let table = base.getTable(tableName);
let view = table.getView(viewName);

// Get exactly the fields visible in this view
let exportFields = ['Name', 'Notes']

// Fetch records with only those fields (best practice)
let query = await view.selectRecordsAsync({
fields: exportFields
});

// Build CSV header
let csv = exportFields.map(f => `"${f}"`).join(",") + "\n";

// Build CSV body
for (let record of query.records) {
let row = exportFields.map(f => {
let val = record.getCellValueAsString(f) ?? "";
return `"${val.replace(/"/g, '""')}"`;
}).join(",");
csv += row + "\n";
}

// Output for the next automation step
output.set("csvContent", csv);

Airtable does let us pull the visible fields in a view via a Script Extension if that helps, but you’d need to manually run that every time


Forum|alt.badge.img+13
  • Author
  • Inspiring
  • November 21, 2025

Thanks ​@TheTimeSavingCo - there are quite a few fields so I was hoping there was a better solution, but I will bite the bullet and give that a go! It seems crazy that there isn’t an automation type that does this as standard.

 

Appreciate the help!

 

@Mike_AutomaticN  - I assume per TheTimeSavingCo’s response that this only works in the script extension (including pulling the fields from the view), but thanks for your response.


Mike_AutomaticN
Forum|alt.badge.img+28

Oh yes, that is correct -only works in the script extension ​@jwag 

Completely different matter, but would love to have you join our Airtable Hackathon! Make sure to sign up!!

Mike, Consultant @ Automatic Nation 
YouTube Channel