Skip to main content

Remove unused select field options easily!

  • February 3, 2023
  • 1 reply
  • 1 view

Lom_Labs

This extension will help you find unused select dropdown data (from either single select or multiple select fields) and delete them!

Base with extension installed

To use it, install the "Script Extension" and paste the code below into it, and a video of how to do that is below

 

Code:

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 = new Object; 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 = new Array let notInUse = new String for(let option of field.options.choices){ if(inUse[option.name]){ updatedOptions.push(option) } else{ notInUse = 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.'); } }

 

1 reply

ScottWorld
Forum|alt.badge.img+20
  • Brainy
  • 8741 replies
  • February 5, 2023

Nice! This is an extremely useful script! 😎 If you get a chance, would you mind sharing this with my community at TableForums.com?


Reply