Hello,
Sorry for my bad english.
II have a beginner’s problem.
I am unable to add a multitude of rows to add to a table by merging two other tables.
I manage to create the function to do it, but airtable blocks beyond 15 lines.
I don’t understand how to do the asynchronous function.
I think we should add each field to an object and then transfer it with the asynchronous functions.
Can you tell me how to create this temporary object with a loop.
Thank you
Here my code
import {
initializeBlock,
useBase,
useRecords,
expandRecord,
TablePicker,
TextButton,} from '@airtable/blocks/ui';
import React, {useState} from 'react';
const BATCH_SIZE = 15;
function Cretionproduits() {
// YOUR CODE GOES HERE
const base = useBase();
const tableLogos = base.getTableByNameIfExists('Logo');
const recordsLogo = useRecords(tableLogos);
const tableSuppports = base.getTableByNameIfExists('Support');
const recordsSuppport = useRecords(tableSuppports);
const tableProduits = base.getTableByNameIfExists('Produits');
const recordsProduit = useRecords(tableProduits);
const champs = useRecords(tableProduits.selectRecords());
const temp = useRecords(tableProduits);
//return <div>jm
</div>;
const produits = recordsLogo.map(logo => {
//return <div>{logo}</div>;
temp = recordsSuppport.map(support => ({
// tableProduits.createRecordAsync({'Ref': logo.name + support.name});
'Ref': logo.name + support.name, // problem here, the sentence above works
}));
});
adddata(tableProduits,temp);
}
async function adddata(table,records) {
let i = 0;
while (i < records.length) {
const recordBatch = records.slice(i, i + BATCH_SIZE);
// awaiting the delete means that next batch won't be deleted until the current
// batch has been fully deleted, keeping you under the rate limit
await table.createRecordsAsync(recordBatch);
i += BATCH_SIZE;
}
}
initializeBlock(() => <Cretionproduits />);