Table of contents

How to automatically delete references to other records in Airtable

Keep your Airtable linked records clean - automatically!

Tired of outdated linked records cluttering your Airtable base? Using PowerImporter, and don't want to have to delete a record in order to remove the references to it?
This free script automatically removes references to items added to a specific view in your Airtable base, ensuring your data stays clean - without manual effort.

Works with any linked record field (single or multiple)
Automatically finds and removes linked records when an item is added to a view
No manual cleanup needed - fully automated!

🛠️ How it works

To help explain how the script works, we will imagine that you have an Airtable base with a blog posts table, and another table with blog categories. Each blog post references several categories in the same cell. In your Categories table, you have a view that shows all your categories.

Your purpose is to remove the references to specific blog categories from the blog posts table, while still keeping these categories in your Categories base - in case you want to use them in the future.

At the moment, if you want to do this automatically in Airtable, you have to delete a category entirely from your table, which triggers Airtable to delete all references to this category.

The script enables you to remove references to your categories, while keeping them in your original table for future use, by adding the categories to an additional view (this will be the trigger). We will assume that you are calling the additional view in your Airtable base "Archived categories".

Whenever an item (e.g., a category) enters the “Archived categories” view, the script:
1️⃣ Finds all linked records referencing the archived item (e.g., in blog posts if you added a blog category to the archived view).
2️⃣ Removes only the archived references while keeping other references in the cells intact
3️⃣ Updates Airtable automatically, 24/7, and within seconds - no manual edits required

This works for any linked record setup - categories, tags, jobs, companies, suppliers, teams, and more!

🚀 Why this script is better than Airtable’s built-in filters and automations

✅Built-in filters such as "Limit record selection to a view" will not work for existing references, only for new ones.

✅ Airtable's native automations can only remove all references from one cell, not selectively delete a link to a record and leave others intact in the same cell.

📥 Get the script & set it up in minutes

1️⃣ Set up your Airtable base

  • Step 1: Ensure you have a table with linked records (e.g., “Blog Posts” linked to “Blog Categories”).
  • Step 2: Create an additional view that filters your items (e.g., “Archived Blog Categories”). This should be a different view from your main view.

2️⃣ Add the Airtable automation

  • Step 1: Go to Airtable → Automations → Create Automation.
  • Step 2: Set the trigger: “When a record enters a view”
    • Table: Your reference table (e.g., “Blog Categories”)
    • View: Your archived view (e.g., “Archived Blog Categories”)
  • Step 3: Add an “Run Script” action and define these input variables:
  1. ArchivedItemName: Select "Name" from the triggering record
  2. ReferencedTable: type the name of the table storing linked records (e.g., “Blog Posts”) manually. Beware of typos!
  3. LinkedRecordField: type the name of the linked record field (e.g., “Categories”) manually. Beware of typos!
  • Step 4: Run the script!

📜 The script

// ✅ Get input variables
let config = input.config();
let REFERENCED_TABLE = config.ReferencedTable;
let LINKED_RECORD_FIELD = config.LinkedRecordField;
let archivedItemName = config.ArchivedItemName;

// 🚀 Step 1: Get the table where the references exist
let referencedTable = base.getTable(REFERENCED_TABLE);
let referencedQuery = await referencedTable.selectRecordsAsync({ fields: [LINKED_RECORD_FIELD] });

// 🔍 Step 2: Find all records that reference the archived item
let recordsToUpdate = [];

for (let record of referencedQuery.records) {
   let linkedRecordObjects = record.getCellValue(LINKED_RECORD_FIELD) || [];
   
   // Extract names and record IDs
   let linkedRecordNames = linkedRecordObjects.map(obj => obj.name);
   let linkedRecordIds = linkedRecordObjects.map(obj => obj.id);

   if (linkedRecordNames.includes(archivedItemName)) {
       // Remove only the archived item while keeping others
       let updatedRecords = linkedRecordObjects.filter(obj => obj.name !== archivedItemName);
       let updatedRecordIds = updatedRecords.map(obj => ({ id: obj.id }));

       recordsToUpdate.push({ recordId: record.id, updatedRecords: updatedRecordIds });
   }
}

// ✅ Step 3: Perform batch updates
if (recordsToUpdate.length > 0) {
   for (let record of recordsToUpdate) {
       await referencedTable.updateRecordAsync(record.recordId, {
           [LINKED_RECORD_FIELD]: record.updatedRecords.length > 0 ? record.updatedRecords : []
       });
   }
}

console.log("🎉 Script execution completed!");

🎬 Watch the demo video (coming soon!)

Want to see the script in action? Watch this quick tutorial showing how to:
✔️ Set up the automation in Airtable
✔️ See outdated references disappear automatically
✔️ Use the script for different use cases (tags, suppliers, categories, etc.)

📌 FAQ

Does this script delete records?

No! It only removes the reference from linked records. The archived item still exists in Airtable.

Can I use this for multiple linked record fields?

Yes! Simply run the automation for each linked field you want to clean up.

What happens if no records need updating?

The script simply skips the update.

🎯 Get started today

🔹 Say goodbye to outdated references in Airtable!
🔹 Set up this script in just a few minutes.
🔹 Works for any linked record field - fully automated!

Check out how to create reference fields for categories, authors & tags when migrating from WordPress to Webflow
check it out