I have created my helloworld block successfully. now i want to create table called my-first-table and add records to it.
I have coded this but it displays error
ReferenceError: table is not defined or ui.tableundefine
import {initializeBlock, useBase, table, createRecordAsync} from '@airtable/blocks/ui';
import React from 'react';
import {base} from '@airtable/blocks';
// Create table called my_first_table with its columns and add records to it.
const tab =table.createRecordAsync(my_first_table);
const tab1 = table.createRecordAsync([{'id': '1'},{'fullname': 'John Henry'},{'title': 'my-first-title'}, {'details': 'my-first-descriptions'}] );
if(tab1){
alert('table and record successfully created and added');
}
Please how do I create table and then add records to it. Again if I want add id column how do I make it to be auto_increment
Hi @Fredrick_Esedo - the problem here is that table is not part of '@airtable/blocks/ui' and, so, cannot be imported. This is what the error is reporting.
But more fundamentally, you can’t create a table within a custom block. If you have created a table (using the regular Airtable UI), can you can create, update, delete records within it, but pretty sure there’s no API to create tables.
JB
If this answers your question, please consider marking the answer as "Solution". If not, please post again. Thanks!
@JonathanBowen Thanks for responding. please how do I create table using the regular Airtable UI,can you show me the tutorial or links or better points me to link where I can create table. thanks
Thanks @andywingrave for responding. your solution does not solve my problem. it seems that I have to create table first some where before creating records. do you know how i can do that.
You’d have to create a table by clicking that button and setting up your fields in the grid view. Then you should be able to write to that table using your custom block. You’ll have to switch your definition of your variable tab to something like this: const tab = base.getTableByNameIfExists('My First Table') , assuming the “My First Table” is indeed the name of your table.
thanks @Kamille_Parks for responding. I have logged in to https://airtable.com/ but I did not see anywhere to create table as you screenshots. please help me may be with direct links on where to create tables… am new to airtable. thanks
Oh okay. So when you log into Airtable you’ll see your “workspaces”, which are a collection of bases. In my case, I have a workspace called “Airtable Community” with 20 bases in it.
Each base contains tables. Therefore, you’ll need to select a base from your workspace to begin working. Since you already seem to have the Custom Blocks environment set up, that is the base you will need to open.