May 25, 2020 11:46 PM
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
May 26, 2020 01:39 AM
Hey! I think you might just need to define table as an object so…
let table = {}
May 26, 2020 02:18 AM
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
May 26, 2020 11:18 AM
@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
May 26, 2020 11:30 AM
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.
May 26, 2020 11:31 AM
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.
May 26, 2020 12:01 PM
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
May 26, 2020 12:08 PM
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.
May 26, 2020 12:09 PM
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