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 records 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 table containing a series of blog posts
- a table containing several blog categories.
Each blog post references several categories. 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 table - in case you want to use them in the future. In the example above, we would want to remove all references to PowerImporter, while keeping the references to Webflow, Airtable and WordPress.
At the moment, Airtable can only delete a reference to a record if:
- the record it refers to is deleted (not practical if you want to keep it for later)
- the reference is removed manually in Airtable (tedious if your record is referenced in multiple cells)
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 a separate view (this will be the trigger for the script to run). 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 (very important)
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!
In our example, the result would be as per our screenshot below:
🚀 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.
- Step : Before you do anything else, we definitely recommend that you backup your Airtable data. You can copy your entire Airtable base, table, or at the very least create a duplicate of your Airtable column containing the references to the Blog categories (in our example).
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:
- ArchivedItemName: Select "Name" from the triggering record
- ReferencedTable: type the name of the table storing linked records (e.g., “Blog Posts”) manually. Beware of typos!
- LinkedRecordField: type the name of the linked record field (e.g., “Categories”) manually. Beware of typos!
- Step 4: Run the script! You can also decide to test the automation first, which we do recommend.
📜 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!");
📌 FAQ
Does this script delete records?
No! It only removes the reference from linked records. The archived item still exists in Airtable, and references can be re-created manually 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.
Do I need an Airtable plan to use a script?
Yes, you will need a paid plan with Airtable to run scripts.
What's the link between this script and PowerImporter?
PowerImporter mirrors changes to your Airtable data in Webflow. However, it cannot delete references in Webflow if they have not been deleted in Airtable first. This is because Airtable can only delete a reference to a record if:
- the record it refers to is deleted (not practical if you want to keep it for later)
- the reference is removed manually in Airtable (tedious if your record is references in multiple cells)
This script enables the removal of references to records in Airtable in an automated way.
Could I do the same manually?
Yes you can. The simplest way is to remove the link to a record manually in your Airtable data. This works well if you have very few records, or very few references to a record. If you have dozens / hundreds / thousands of records that reference each other, and you need to find and remove links to records manually, this will be tedious and prone to human error. This script does it all automatically for you.