Best way to modify a multiple select?

Right now I have a multiple select field as follows:
image

The script I’m trying to run has already identified the record IDs of all records with “Split Invoice” as a status.

What I’m trying to do now is to remove that split invoice status and leave the rest (For example Estimated, Invoiced, those can all stay).

What’s the best way to do this? All I can think of is to create an array of all statuses except for “Split Invoice” but I’m not sure how to write the syntax for that either. Code below:

let table = base.getTable("Items");
let queryResult = await table.selectRecordsAsync();

var rec_IDs = []
var rec_names = []
for (let record of queryResult.records) {
    try {
        for (let status of record.getCellValue("Status")) {
            if (status.name === "Split Invoice") {
                rec_IDs.push(record.id);
                rec_names.push(record.name);
            }
        }
    } catch(e) {
        {
            continue;
        }
    }
}
// Script operations go here
// As a final step, remove "Split Invoice"

So if possible I’d like to use the array of rec_IDs to update the Status field to have the exact same values, minus “Split Invoice”, but I’m drawing blanks here. Any pointers would be hugely appreciated, thank you.

Welcome to the community, @Tyler_Thorson! :smiley: This should work:

let table = base.getTable("Items")
let queryResult = await table.selectRecordsAsync({fields: ["Status"]})

const updates = queryResult.records.filter(record => {
    const currentOptions = record.getCellValue("Status") || []
    const newOptions = statusOptions.filter(opt => opt.name !== "Split Invoice")
    if (currentOptions.length !== newOptions.length)
        return {
            id: record.id,
            fields: {
                "Status": newOptions
            }
        }
})

while (updates.length)
    await table.updateRecordsAsync(updates.splice(0, 50))
1 Like