Help

Upcoming database upgrades. to improve our reliability at 03:30 UTC on Feb. 25 / 7:30pm PT on Feb. 24. Some users may briefly experience slow load times or error messages. Learn more here

Link multiple records from array of records IDs

Topic Labels: Scripting extentions
1227 2
cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to, with scripting, link multiple records to one record. The code I have below succesfully links one record, and I’ve tried using a for loop, as well as a forEach to get it to cycle through the record Ids in the ‘matchTKRecords’ array. I’ve attached a picture of the console.log output for the matchingTKRecords array.

To clarify - my aim is to link the VMrecordID record to any/all of the records in matchingTKrecords

The error I get is always some variation on:
Error: Field "Linked tickets" cannot accept the provided value. at main on line 46

what I don’t understand is why an array of record IDs is not accepted as a write value for a linked tickets field (it is set-up correctly as a ‘link to another record’ field). Linking to multiple records is enabled

let newForeignRecordIdToLink = matchingTKRecords[0].id;
VMtable.updateRecordAsync(config.VMrecordID, {
'Linked tickets': [{ id: newForeignRecordIdToLink }]
   
})

consolelog

Thank you in advance for any assistance!

2 Replies 2

You’re passing an array of objects that includes the name property. The objects should only include the id property (which is why your example linking the first from that array works).

Without seeing the rest of the code, you will likely have to do something like this:

let newRecordIdsToLink = matchingTKRecords.map(record => ({id: record.id}));
VMtable.updateRecordAsync(config.VMrecordID, {
    'Linked tickets': newRecordIdsToLink
})

Thanks for the response! I changed the code as follows:

let newForeignRecordIdToLink = matchingTKRecords.map(record => ({id: record.id}));

await VMtable.updateRecordAsync(config.VMrecordID, {

    'Linked tickets': [{ id: newForeignRecordIdToLink }]

   

})

However I get the error:

### ERROR

Error: Field "Linked tickets" cannot accept the provided value.

at main on line 61

EDIT: Realised my mistake - should be

let newForeignRecordIdToLink = matchingTKRecords.map(record => ({id: record.id}));

await VMtable.updateRecordAsync(config.VMrecordID, {

    'Linked tickets': newForeignRecordIdToLink

})

As you indicated! Thank you so much!