Help

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

Solved
Jump to Solution
2931 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Anton_Pettersso
6 - Interface Innovator
6 - Interface Innovator
Hello! I don't understand why the linked field won't accept the value. What am I missing?
Screenshot 2023-09-08 at 11.44.31.png
 
 
//Setup Start
let tableName = "🎵 Tracks"
let linkedField1Name = "Composer(s)"
let linkedField2Name = "Producer(s)"
let compiledLinkedFieldName = "Contributors (-mix)"
//Setup End

let {linkedField1Values, linkedField2Values, recordId} = input.config()

let table = base.getTable(tableName)

let compiledObject = new Object;

for (let record of linkedField1Values){
compiledObject[record] = recordId
console.log(record)
}

for (let record of linkedField2Values){
compiledObject[record] = recordId
}

let compiledArray = new Array;

for (let record in compiledObject){
compiledArray.push({id: record})
}

await table.updateRecordAsync(recordId, {
"Contributors (-mix)": compiledArray
})
1 Solution

Accepted Solutions
Anton_Pettersso
6 - Interface Innovator
6 - Interface Innovator

Solved it now by removing the push update and having the script output the result instead, then updating the record via Update Record action in the same automation. But thank you for your time and effort Sho!

//Setup Start
let tableName = "🎵 Tracks"
let linkedField1Name = "Composer(s)"
let linkedField2Name = "Producer(s)"
let compiledLinkedFieldName = "Unique Combinations"
//Setup End

let {linkedField1Values, linkedField2Values, recordId} = input.config()

let table = base.getTable(tableName)

let compiledObject = new Object;

for (let record of linkedField1Values){
    compiledObject[record] = recordId
}

for (let record of linkedField2Values){
    compiledObject[record] = recordId
}

let compiledArray = new Array;

for (let record in compiledObject){
    compiledArray.push({id: record})
}

console.log(compiledArray)

output.set("compiledArray", compiledArray);

 

See Solution in Thread

10 Replies 10
Sho
11 - Venus
11 - Venus

Hi @Anton_Pettersso,

Linked table fields cannot have duplicate values.
Add an IF statement or use "[...new Set(compiledObject)]" to exclude duplicate values.

Sho
11 - Venus
11 - Venus
for (let record of compiledObject){
  compiledArray.push({id: record})
}

And, it's "of" here, not "in".
Check it out in console.log.

Hey Sho, not sure how I would integrate that. Could you show me where in the script to add this?

Sho
11 - Venus
11 - Venus

I've asked chat-gpt to do this for you.
It seems that by converting from object to array, duplicate values are not possible.

// Setup Start
let tableName = "🎵 Tracks";
let linkedField1Name = "Composer(s)";
let linkedField2Name = "Producer(s)";
let compiledLinkedFieldName = "Contributors (-mix)";
// Setup End

let { linkedField1Values, linkedField2Values, recordId } = input.config();

let table = base.getTable(tableName);

let compiledObject = {};

for (let record of linkedField1Values) {
  compiledObject[record.id] = { id: record.id };
}

for (let record of linkedField2Values) {
  compiledObject[record.id] = { id: record.id };
}

let compiledArray = Object.values(compiledObject);

await table.updateRecordAsync(recordId, {
  [compiledLinkedFieldName]: compiledArray,
});

 

Hah, I checked with chat-gpt and Bard as well, without any luck. And I get the same error message with this script...

Sho
11 - Venus
11 - Venus

Maybe "Composer(s)" and "Producer(s)" are different tables?

Anton_Pettersso
6 - Interface Innovator
6 - Interface Innovator

No, same table. I made a copy of the setup in a new base here.

Anton_Pettersso
6 - Interface Innovator
6 - Interface Innovator

Solved it now by removing the push update and having the script output the result instead, then updating the record via Update Record action in the same automation. But thank you for your time and effort Sho!

//Setup Start
let tableName = "🎵 Tracks"
let linkedField1Name = "Composer(s)"
let linkedField2Name = "Producer(s)"
let compiledLinkedFieldName = "Unique Combinations"
//Setup End

let {linkedField1Values, linkedField2Values, recordId} = input.config()

let table = base.getTable(tableName)

let compiledObject = new Object;

for (let record of linkedField1Values){
    compiledObject[record] = recordId
}

for (let record of linkedField2Values){
    compiledObject[record] = recordId
}

let compiledArray = new Array;

for (let record in compiledObject){
    compiledArray.push({id: record})
}

console.log(compiledArray)

output.set("compiledArray", compiledArray);

 

Sho
11 - Venus
11 - Venus

Congrats!
I didn't know how to set variables in this way of writing, so I learned a lot too.

let {linkedField1Values, linkedField2Values, recordId} = input.config()