Help

Re: Error: Field [linked record] cannot accept the provided value. Multiple Select Field.

Solved
Jump to Solution
433 0
cancel
Showing results for 
Search instead for 
Did you mean: 
PauB
5 - Automation Enthusiast
5 - Automation Enthusiast

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.`);
}

 

 

 

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

Try updating your 'selectedOptions' line like so:

let selectedOptions = [{name: "AI"} , {name: "Augmented Reality"}];

 

See Solution in Thread

3 Replies 3
TheTimeSavingCo
18 - Pluto
18 - Pluto

Try updating your 'selectedOptions' line like so:

let selectedOptions = [{name: "AI"} , {name: "Augmented Reality"}];

 

Pay attention to a difference between cell read format and cell write format. 
You receive array of objects with  id, name and color (color can be absent)
To write, you should prepare array of objects with name only  (or with id only)

    let currentValues = record.getCellValue(fieldName) || [];
console.log(currentValues)
    let newValues = [
        ...currentValues.filter(opcion => selectedOptions.includes(opcion)),
        ...selectedOptions.filter(opcion => !currentValues.includes(opcion))
    ];
console.log(newValues)
let writeValues=newValues.map(value=>( {id:value.id} ))
//also can be written as: let writeValues=newValues.map( ({name,...rest})=>({name}) )
//when you put {object} in arrow-function, it must be enclosed in round brackets
    await table.updateRecordAsync(recordId, {
        [fieldName]: writeValues
PauB
5 - Automation Enthusiast
5 - Automation Enthusiast

Cool! Thanks to all.