Apr 11, 2021 10:26 PM
Hi! I’m trying to automatically link records through a script created by @Justin_Barrett (Automatically link record based on plain text or formula result).
But I can’t run the script as I get errors in the last line: Property ‘id’ does not exist on type ‘string | SitesTable_Record’. / Property ‘id’ does not exist on type ‘string’
What could be the problem? I have no knowledge about scripting…
Thanks!
Apr 12, 2021 12:08 PM
Could you share the modified script that you’re trying to use? (After pasting the script into the post editor, please format it using the “Preformatted Text” option in the toolbar, which looks like this: </>
)
Apr 12, 2021 09:11 PM
Thanks, Justin.
The script:
let checkin123Table = base.getTable("Check-in - LPSI 1/2/3");
let consignorTable = base.getTable("Consignor");
let consignorQuery = await consignorTable.selectRecordsAsync();
let config = input.config();
// Find the matching record
let matched = consignorQuery.records.filter(consignor => {return consignor.name === config.consignorName});
let consignorRecord;
// If a matching record exists, use it; otherwise make a new record
if (matched.length)
consignorRecord = matched[0];
else
consignorRecord = await consignorTable.createRecordAsync({"Name": config.consignorName});
await checkin123Table.updateRecordAsync(config.recordID, {"Consignor": [{id: consignorRecord.id}]});
Apr 12, 2021 09:11 PM
Apr 12, 2021 09:29 PM
I see the problem. When you create a record, Airtable doesn’t return a record object with an id
property. It just returns the record ID as a string. Apparently the return was a record object when I wrote that script, but unfortunately I can’t edit that post to include a caveat with the current behavior.
Because of that change, the last few lines need to be modified:
if (matched.length)
consignorRecord = matched[0].id;
else
consignorRecord = await consignorTable.createRecordAsync({"Name": config.consignorName});
await checkin123Table.updateRecordAsync(config.recordID, {"Consignor": [{id: consignorRecord}]});
Apr 12, 2021 09:39 PM
Thanks!
But now I’m getting another error, in the 4th line, let config = input.config(); - “An argument for ‘options’ was not provided”
let checkin123Table = base.getTable("Check-in - LPSI 1/2/3");
let consignorTable = base.getTable("Consignor");
let consignorQuery = await consignorTable.selectRecordsAsync();
let config = input.config();
Apr 12, 2021 09:52 PM
Are you trying to use this script in the Scripting app? It’s designed to be used as a scripting action in an automation. Both systems use input.config()
, but in very different ways and with different requirements for correct setup.
Apr 12, 2021 11:53 PM
Oh… yes!!
I just used the script as a scripting action and I get this error:
ERROR
TypeError: Invalid arguments passed to table.updateRecordAsync(recordOrRecordId, fields):
• recordOrRecordId →
recordOrRecordId should be a Record, not undefined
or recordOrRecordId should be a string, not undefined
at main on line 15
May 15, 2021 03:18 PM
Sorry for the delayed response. Unfortunately I’ve been—and continue to be for the foreseeable future—pretty swamped, and I can’t look into this any further. Maybe @kuovonne or @Kamille_Parks or @JonathanBowen or @Jeremy_Oglesby can help?
Sep 17, 2021 10:20 AM
Happened to me today when trying to run studentTable.updateRecordAsync()
with a recordId that is null/undefined.