Help

Re: Best way to modify a multiple select?

Solved
Jump to Solution
1348 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Tyler_Thorson
6 - Interface Innovator
6 - Interface Innovator

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.

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

Welcome to the community, @Tyler_Thorson! :grinning_face_with_big_eyes: 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))

See Solution in Thread

2 Replies 2
Justin_Barrett
18 - Pluto
18 - Pluto

Welcome to the community, @Tyler_Thorson! :grinning_face_with_big_eyes: 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))
Katie
4 - Data Explorer
4 - Data Explorer

Can I get all of your script for identifying the records with "split invoice" and the code you used to remove that status? I am working on a very similar situation, but am a novice at coding. Any help would be greatly appreciated.