Skip to main content
Solved

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


Forum|alt.badge.img+7
Hello! I don't understand why the linked field won't accept the value. What am I missing?
 
 
//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
})

Best answer by Anton_Pettersso

Sho wrote:

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


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);

 

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

10 replies

Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • September 8, 2023

Hi @Anton_Pettersso,

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


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • September 8, 2023
for (let record of compiledObject){ compiledArray.push({id: record}) }

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


Forum|alt.badge.img+7
Sho wrote:

Hi @Anton_Pettersso,

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


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


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • September 12, 2023

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, });

 


Forum|alt.badge.img+7
Sho wrote:

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...


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • September 14, 2023

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


Forum|alt.badge.img+7
Sho wrote:

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


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


Forum|alt.badge.img+7
  • Author
  • Inspiring
  • 7 replies
  • Answer
  • September 14, 2023
Sho wrote:

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


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);

 


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • September 14, 2023

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()

 


salvadaor
Forum|alt.badge.img+5
  • Participating Frequently
  • 13 replies
  • October 4, 2023
Anton_Pettersso wrote:

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);

 


Rad, this helped me solve a similar issue I was facing regarding linked records in the automation environment.

 


Reply