Help

Re: Linking records with script

2845 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Livraria_Portug
5 - Automation Enthusiast
5 - Automation Enthusiast

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!

9 Replies 9

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: </>)

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

Table1 Table2

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

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

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.

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

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?

Happened to me today when trying to run studentTable.updateRecordAsync() with a recordId that is null/undefined.