I’m trying to use the scripting app to:
- Get all of the records from one table (this Table is called “Incoming”)
- Copy all the records from the Incoming table to a different table called “Copied”
Here is my code:
let tableIncoming = base.getTable('Incoming');
let tableCopied = base.getTable('Copied');
let query = await tableIncoming.selectRecordsAsync();
let arrayOfIds = query.recordIds;
let records = query.records;
let recordsWithFields = [];
console.log('query:', query);
console.log('arrayOfIds:', arrayOfIds);
for (const record of records) {
let newRecord = {
"id": record.id,
"fields": record,
};
recordsWithFields.push(newRecord);
console.log('recordsWithFields', recordsWithFields);
}
/////
let recordsObject = { records: recordsWithFields };
console.log('recordsObject', recordsObject);
await tableCopied.createRecordsAsync(recordsWithFields);
However, I’m getting the following error: Invalid record format. Please define field mappings using a
fields key for each record definition object
I think the data I am passing into createRecordsAsync
is formatted incorrectly? I that guess correct? If so, how should it be formatted? If not, what am I doing wrong?
Also, is there any documentation? I got all of this from watching YouTube videos and reading code in other Airtable apps trying to find pieces that are relevant to me which is pretty inefficient. Any help would be greatly appreciated!