Hi all,
I am using the Spreadsheet Importer in the Scripting Extension to upload an XLSX file to create new records in my table (“Report Data”). One of the fields in this XLSX report is a Customer ID. That should be a linked field to a table called “Customer IDs”.
After going through a few different threads, I declared the following variables to create a “Dictionary” array of the Customer IDs (primary field) & their RecordIDs:
let IDTable = base.getTable("Customer IDs");
let IDQuery = await IDTable.selectRecordsAsync();
let IDDict = {};
for (let record of IDQuery.records) {
IDDict[record.name] = record.id;
}
Then when I am mapping the fields I am declaring that field like so:
let newRecords = xlsxRows.map(xlsxRow => ({
fields: {
'Customer ID': [{ id: IDDict[String(xlsxRow['Customer ID'])] }]
}
}));
This works… only IF the ID already exists. If an ID is new, I get the following error:
j: Can't create records: invalid cell value for field 'Customer ID'.
Cell value has invalid format: <root>.0.0.id is missing.
Linked records field value must be an array of objects with property 'id' corresponding to linked record id.
at main on line 143
Is there any way I can modify this code so that it links to the existing record if it exists, but creates a new record if it does not exist? I am able to achieve this via automation but can’t figure it out with scripting.
Thanks in advance!
