capt wrote:
Hi @JonathanBowen thanks for the reply, I was not online yesterday :slightly_smiling_face:
Here are two screen grabs:

This shows the table right now, I copied it and called it ‘Source 2’. This shows a Single Text field ‘Data’ that copies into field ‘Data 2’, also a Single Text field, shown by the green arrow.
The top two records have been actioned with the ‘Copy’ Button and you can see the 'Created date in the ‘Data’ field after the Run. The data should copy and paste into linked ‘Repository’ field (red arrow), which is the primary field (Single Text) in the Repository Table. So the error ‘string’ is not assignable to type '{ id: string; } happens when I use the linked field as target.
It occured to me that I need to create the linked field entry from a Formula field not Single Text. So I modified the table ‘Source’ to how I want the final version to work:

The Formula is similar to the one shown here, two SIngle Text fields ‘Part 1’ and ‘Part 2’ are combined into a part code in field ‘Data’. That part code should then be copied to the linked field ‘Repository’ to create that part entry in the ‘Repository’ table, which has other lookup fields to create a parts register. Right now the code does not function on pasting to a linked field but also does not work on the formula field.
I can understand the code by trial and error, but my knowledge does not extend to fixing this.
Hope this makes sense, thanks for your help
Tom
Hi Tom - a few points that might help:
- you might not need the data field if this is just a way to join “part1” with “part2”. You could do this in the script directly:
let record = await input.recordAsync('Pick a record', sourceT);
let name = record.getCellValue('Part 1') + '-' + record.getCellValue('Part 2');
console.log(name);
- As you are running the script against a single selected record you don’t need this part of the script (which selects all records from the table):
let parts= await partField.selectRecordsAsync();
- You can’t copy a string value into a linked field. When you populate a linked record field in table A, referring to table B, there’s an assumption that you know the ID of the record in table B already and if you do know this, then the format would be:
let updatedRecord = await table.updateRecordAsync(record, {
'Repo': [{id: idFromTableB}]
})
“idFromTableB” will take to form “recXXXXXXXXXXXXXX” - the internal Airtable record ID. To update a linked field you need an array of objects (as there could be more than one) and each object is of the form:
{id: someRecordId}
From what I understand though, the value created from part 1 and part 2 does not yet exist in the repo table, right? In which case you need to create it first (in the repo table), then link it (in the source table). This isn’t as hard as it might first appear!
let repoT = base.getTable('Repo');
let sourceT = base.getTable('Source');
let record = await input.recordAsync('Pick a record', sourceT);
let name = record.getCellValue('Part 1') + '-' + record.getCellValue('Part 2');
let newRepoRecord = await repoT.createRecordAsync({
'Name': name
})
console.log(newRepoRecord);
let updatedRecord = await sourceT.updateRecordAsync(record, {
'Repo': [{id: newRepoRecord}]
})
-
What if your new value already exists in the repo table? The above code will just create a duplicate record in repo table which probably isn’t what you want. If there’s a possibility of the same “data” value occurring more than once then instead creating the newRepoRecord
you will need to check if this value exists in repo
already - if it does, then get its id; if it doesn’t then create it and get its id (this is what we did above).
-
Final point - I wouldn’t overwrite the “data” field with the created date value. In doing this, you’re using one field for two different things, which I tend to think is a bad idea. What I would do is create a new date field in the source table “Created in repo date” and just set this to be the date when it was created. You can do this in the update:
let updatedRecord = await sourceT.updateRecordAsync(record, {
'Repo': [{id: newRepoRecord}],
'Created in repo date': now
})
For info, this is my (simplified) table:

Hope that helps!
=======================
Want to learn Airtable Scripting? 1 day bootcamp coming soon!
=======================