Skip to main content
Solved

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


  • New Participant
  • 2 replies

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

 

 

 

Best answer by TheTimeSavingCo

Try updating your 'selectedOptions' line like so:

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

 

View original
Did this topic help you find an answer to your question?

3 replies

TheTimeSavingCo
Forum|alt.badge.img+18

Try updating your 'selectedOptions' line like so:

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

 


Alexey_Gusev
Forum|alt.badge.img+12
  • Inspiring
  • 1111 replies
  • July 29, 2024

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

  • Author
  • New Participant
  • 2 replies
  • July 30, 2024

Cool! Thanks to all.


Reply