Hi @MontanaGeek,
This one is quite interesting. I wasn’t aware there was a deleteFieldAsync function in the Airtable API. I can’t find it in any documentation online. I’m curious to see the script you had that gave you the error message you showed. Has anyone else seen this function before?
Hi @airvues
Sure thing, here is the code below: (change Dry run to false for it to apply changes)
/***** SETTINGS *****/
const DRY_RUN = true; // ← set to false to actually delete fields
const MATCH_TEXT = "(SS)"; // delete any field whose name CONTAINS this text (case-sensitive)
const REQUIRE_CONFIRM = true; // when live, require typing DELETE to confirm
/***** TABLE *****/
const TABLE_NAME = "Form Questions";
const table = base.getTable(TABLE_NAME);
/***** CAPABILITY CHECK *****/
const canDelete = (typeof table.deleteFieldAsync === "function");
output.text(`deleteFieldAsync available: ${canDelete ? "yes" : "no"}`);
if (!canDelete && !DRY_RUN) {
output.text("
Your current environment/role does not support deleting fields via script.");
output.text(" Please run this in Extensions → Scripting with a Creator role, or delete the fields manually.");
// Fall through to list targets so you can delete manually
}
/***** FIND TARGET FIELDS *****/
const targets = table.fields.filter(f => f.name.includes(MATCH_TEXT));
if (targets.length === 0) {
output.text(`No fields in "${TABLE_NAME}" contain "${MATCH_TEXT}".`);
return;
}
output.text(`Found ${targets.length} field(s) to delete (name contains "${MATCH_TEXT}"):\n`);
targets.forEach(f => output.text(" - " + f.name));
if (DRY_RUN) {
output.text("\nDRY RUN: no fields were deleted. Set DRY_RUN = false to proceed.");
return;
}
if (!canDelete) {
output.text("\nDeletion not supported in this environment. Please delete the above fields manually.");
return;
}
/***** OPTIONAL CONFIRMATION *****/
if (REQUIRE_CONFIRM) {
const typed = await input.textAsync(
`\nType DELETE to remove ${targets.length} field(s) from "${TABLE_NAME}". This is IRREVERSIBLE.`
);
if ((typed || "").trim().toUpperCase() !== "DELETE") {
output.text("Cancelled. No fields were deleted.");
return;
}
}
/***** DELETE LOOP *****/
let deleted = 0, failed = 0;
for (const f of targets) {
try {
await table.deleteFieldAsync(f);
output.text(`
Deleted: ${f.name}`);
deleted++;
} catch (e) {
output.text(`
Failed: ${f.name} → ${e}`);
failed++;
}
}
/***** SUMMARY *****/
output.text("\n--- SUMMARY ---");
output.text(`Deleted: ${deleted}`);
output.text(`Failed: ${failed}`);
Thanks for sharing that script @MontanaGeek. Not sure where you got that script but essentially the error message you get from running it comes from the script itself. The script checks if deleteFieldAsync is a function within Airtables api, but that check results in false which is why you get “deleteFieldAsync available: no”.
Then the rest of the error message is a result that the function doesn’t exist and the fact that a variable DRY_RUN is set to true.
I believe this script was built with the idea that deleteFieldAsync might not exist, but if it were to exist then it has all the logic to actually use that function on all fields that have those keywords.
TLDR, there’s actually not a current way to delete fields in Airtable programmatically, you can only delete them manually.
Sounds good, thank you for looking at this.