Scripting
Model

Base

A Base provides an entry point to all of the data in a given base. There is only ever one base available—the base in which this script is installed. It can be accessed via the base global variable. You can use it to get data from your base, like tables, views, fields, and records.

Example
console.log(`The name of my base is ${base.name}.`);
console.log(`It contains ${base.tables.length} tables.`);

id

typedef
string

The unique ID of your base.

name

typedef
string

The name of your base.

activeCollaborators

typedef
Array<Collaborator>

The users who have access to this base.

Example
// show a table of all the base collaborators:
console.log('# All collaborators:');
console.log(base.activeCollaborators);

tables

typedef
Array<Table>

The tables in this base.

Example
// log every table's name and id from the base
for (let table of base.tables) {
console.log(`Table '${table.name}' has id '${table.id}'.`);
}

getCollaborator

function
function (idOrNameOrEmail: string) => Collaborator;
Parameter nameDescription
idOrNameOrEmailThe id, name, or email address of the user collaborator you want to retrieve.

Get a user collaborator, that is shared either directly or indirectly via a user group, from the base according to their ID, name, or email.

Example
// Get collaborator by id:
let collaborator1 = base.getCollaborator("usrY95cZelCe1HuqR");
console.log(collaborator1);
// Get collaborator by name:
let collaborator2 = base.getCollaborator("Casey Park");
console.log(collaborator2);
// Get collaborator by email:
let collaborator3 = base.getCollaborator("sandy.hagen@airtable.com");
console.log(collaborator3);

getTable

function
function (idOrName: string) => Table;
Parameter nameDescription
idOrNameThe id or name of the table you want to retrieve.

Get a table from the base according to its ID or name.

Example
// Get table by id:
let table1 = base.getTable("tbluPmFGLSpnEPMHO");
console.log(table1);
// Get table by name:
let table2 = base.getTable("Projects");
console.log(table2);

createTableAsync
Scripting Extension only

function
(name: string, fields: Array<{name: string, type: FieldType, options?: {[key: string]: unknown} | null, description?: string | null}>) => Promise<string>
Parameter nameDescription
nameName for the table. Must be case-insensitive unique
fieldsArray of fields to create in the table. See below for details.

Creates a new table.

Throws an error if the user does not have permission to create a table, if an invalid table name is provided, or if invalid fields are provided (invalid name, type, options or description).

At least one field must be specified. The first field in the fields array will be used as the table's primary field and must be a supported primary field type. Fields must have case-insensitive unique names within the table.

The following field types can be created:

  • checkbox
  • singleSelect
  • multipleSelects
  • singleCollaborator
  • multipleCollaborators
  • number
  • percent
  • currency
  • duration
  • singleLineText
  • email
  • url
  • multilineText
  • phoneNumber
  • richText
  • barcode
  • multipleAttachments
  • date
  • dateTime
  • rating
  • multipleRecordLinks

The following field types cannot be created:

  • formula
  • createdTime
  • rollup
  • count
  • multipleLookupValues
  • autoNumber
  • lastModifiedTime
  • button
  • createdBy
  • lastModifiedBy
  • externalSyncSource
  • aiText

Refer to Cell values & field options for the write format for field options and other specifics for certain field types.

name and type must be specified for all fields, while options is only required for fields that have field options. description is optional and will be '' if not specified or if specified as null.

A default grid view will be created with all fields visible.

This action is asynchronous: you must add await before each call to this method to ensure it takes effect.

Example
const tableId = await base.createTableAsync("Tasks", [{name: "Title", type: "singleLineText"}]);