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

Basic Filter
let table = base.getTable("Tasks");
let query = await table.selectRecordsAsync();

// Filter by status
let filtered = query.records.filter(record => record.getCellValue("Status") === "Open");

for (let record of filtered) {
    output.text(`Open Task: ${record.name}`);
}
Keyword Search
let table = base.getTable("Projects");
let searchTerm = await input.textAsync("Enter a keyword to search:");
let records = await table.selectRecordsAsync();

let matched = records.records.filter(record =>
    record.name.toLowerCase().includes(searchTerm.toLowerCase())
);

if (matched.length === 0) {
    output.text("No matches found.");
} else {
    matched.forEach(rec => output.text(`Found: ${rec.name}`));
}

Prompt with Continue / Abort
// Place logic here
output.text("Plan to execute...");
let confirmed = await input.buttonsAsync("Do you want to proceed?", ["Continue", "Abort"]);
if (confirmed === "Abort") {
    output.text("Script aborted.");
    return;
}

// Place logic here
output.text("Continuing the script...");
Create New Record with Input
let table = base.getTable("Ideas");

let ideaName = await input.textAsync("Enter the idea name:");
let category = await input.textAsync("Enter category:");

await table.createRecordAsync({
    "Name": ideaName,
    "Category": category
});

output.text("Idea submitted!");
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]