The objective of the code is to select the options that are in the array for a multiple select field. I don't understand why it never allows adding options even if they are exactly the same as those in the table. It is an automation script. Thanks in advance for the help.
let table = base.getTable("TABLE"); // the table is correct
let fieldName = "Technology";
let recordId = "recXXXXXXXXXXXXXX"; // the record id is correct
let selectedOptions = ["AI", "Augmented Reality"];
let record = await table.selectRecordAsync(recordId);
if (record) {
let currentValues = record.getCellValue(fieldName) || [];
let newValues = [
...currentValues.filter(opcion => selectedOptions.includes(opcion)),
...selectedOptions.filter(opcion => !currentValues.includes(opcion))
];
await table.updateRecordAsync(recordId, {
[fieldName]: newValues
});
console.log(`Record ${recordId} updated with options: ${newValues.join(", ")}`);
} else {
console.log(`Record with ID: ${recordId} does not exist.`);
}