Jul 26, 2022 04:16 PM
Right now I have a multiple select field as follows:
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.
Solved! Go to Solution.
Aug 01, 2022 10:24 PM
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))
Aug 01, 2022 10:24 PM
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))
Dec 09, 2022 09:05 AM
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.