Cannot create table and add records to it

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

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

Hey! I think you might just need to define table as an object so…

let table = {}

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.


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.

I believe Jonathan is refering to the “Create New Table” button at the top of Airtable’s user interface:

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.

1 Like

thanks @Kamille_Parks for responding. I have logged in to 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.

1 Like

Hey Fredrick,

You first need to create the base, then you need to create the table from within the base.

You can either use one of the templates that exist or create your own.

Once you do create a base, you’ll see the option Kamille pointed out, above

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.