How to remove unused options from select fields in Airtable.

Say you have an Airtable base with tables containing Single & Multiple Select fields containing options that are no longer in use.

Here’s how to remove them all in one go.

Step 1

Inside your Airtable base, click: Tools > Extensions > Add an extension.

Step 2

Search for Scripting and add it to your base.

Step 3

Copy and paste this code into the scripting panel.

let settings = input.config({

title: `Identify and remove select field options that are not in use`,

items: [

input.config.table("table", { label: `Table` }),

input.config.field("field", { parentTable: `table`, label: `Field` }),

],

});

let { table, field } = settings;

let fieldData = table.getField(field.id);

let fieldType = fieldData.type;

if(fieldType != "singleSelect" && fieldType != "multipleSelects") throw("Only works with single select or multiple select fields");

let query = await table.selectRecordsAsync({fields: [field]});

let inUse = {};

for (let r of query.records){

let selectedOptions = r.getCellValue(field);

if(selectedOptions){

if(fieldType === "multipleSelects"){

for(let option of selectedOptions){

inUse[option.name] = 1;

}

} else {

inUse[selectedOptions.name] = 1;

}

}

}

let updatedOptions = [];

let notInUse = "";

for(let option of field.options.choices){

if(inUse[option.name]){

updatedOptions.push(option);

} else {

notInUse += "\n - " + option.name;

}

}

if(notInUse === ""){

output.text("All select field options are in use");

} else {

output.text("The following options are not in use:" + notInUse);

let proceed = await input.buttonsAsync('Proceed with deletion of the listed options? *CAUTION: This cannot be undone.*', ['Delete', 'Do nothing']);

if (proceed === "Delete") {

output.text('Deleting..');

await field.updateOptionsAsync(

{choices: updatedOptions},

{enableSelectFieldChoiceDeletion: true},

);

output.text('Done');

} else {

output.text('Nothing deleted. Ending.');

}

}

Step 4

Upon pasting the code from Step 3, you should now see a panel allowing you to select a Table and a Field containing the unused tags. Click Run.

Step 5

The script will list options that are not in use. To confirm deleting them, click Delete (this is a permanent move).

If all options are in use, a message showing “All select field options are in use” will appear.

Previous
Previous

How to combine multiple .md files into one .txt file.

Next
Next

How to bulk rename files into ordered numbers in MacOS.