Airtable Scripting

Automating Tasks with Scripts



Scripting

Airtable scripting allows you to automate tasks and extend the functionality of your bases using JavaScript. Whether you need to perform complex calculations, integrate with external services, or create custom workflows, scripts can help you achieve these goals.


Getting Started

[Content will go here]


Scripts

[Content will go here]


Automation Scripting Examples


Extension Scripting Examples

Calculate Total Table Usage
let total = 0;
let tables = base.tables;

for (let table of tables) {
    let query = await table.selectRecordsAsync();
    total += query.records.length;
    output.text(`${table.name}: ${query.records.length} records`);
}

output.text(`\nTotal records across all tables: ${total}`);
Total Usage with Estimations
// === CONFIG ===
let estimatedDailyGrowth = 50; // ๐Ÿ‘ˆ Change this to your average daily new rows
let maxRowsAllowed = 50000;    // ๐Ÿ‘ˆ Change based on your Airtable plan

// === COUNT RECORDS ===
let total = 0;
let tables = base.tables;
output.markdown("### ๐Ÿ“‹ Rows by Table");

for (let table of tables) {
    let query = await table.selectRecordsAsync();
    output.text(`${table.name}: ${query.records.length} records`);
    total += query.records.length;
}

output.markdown(`\n**๐Ÿงฎ Total rows:** ${total} / ${maxRowsAllowed}`);

let remaining = maxRowsAllowed - total;
let daysLeft = estimatedDailyGrowth > 0 ? Math.floor(remaining / estimatedDailyGrowth) : 'โˆž';

output.markdown(`**๐Ÿ“ˆ Est. daily growth:** ${estimatedDailyGrowth} rows/day`);
output.markdown(`**๐Ÿ•’ Days until limit:** ${daysLeft} days`);
Export Tables Fields and Details in Markdown Format
let tables = base.tables;

let markdownOutput = '## Airtable Schema Overview\n\n';

for (let table of tables) {
    markdownOutput += `### ๐Ÿ“„ Table: ${table.name}\n\n`;
    markdownOutput += '| Field Name | Type | Description | Default Value | Options |\n';
    markdownOutput += '|------------|------|-------------|---------------|---------|\n';

    for (let field of table.fields) {
        let options = '';

        if (field.type === "singleSelect" || field.type === "multipleSelects") {
            options = field.options?.choices ? field.options.choices.map(opt => opt.name).join(", ") : '';
        }

        let description = field.description ? field.description : 'N/A';
        let defaultValue = field.defaultValue ? field.defaultValue : 'N/A';

        markdownOutput += `| ${field.name} | ${field.type} | ${description} | ${defaultValue} | ${options} |\n`;
    }

    markdownOutput += '\n---\n';
}

// Output the result
output.text(markdownOutput);


Best Practices and Tips

[Content will go here]