Extensions

Press shift + S to search API reference.

Model

Model class representing a record in a table.

Do not instantiate. You can get instances of this class by calling table.selectRecords or view.selectRecords and using the resulting RecordQueryResult.

Members

class Record extends AbstractModel<RecordData, WatchableRecordKey>
readonly commentCountnumber

The number of comments on this record.

const commentCount = myRecord.commentCount;
const isSingular = commentCount === 1;
console.log(
`This record has ${commentCount} comment${isSingular ? '' : 's'}`
);
readonly createdTimeDate

The created time of this record.

console.log(`
This record was created at ${myRecord.createdTime.toISOString()}
`);
readonly idstring

The ID for this model.

readonly isDeletedboolean

true if the model has been deleted, and false otherwise.

In general, it's best to avoid keeping a reference to an object past the current event loop, since it may be deleted and trying to access any data of a deleted object (other than its ID) will throw. But if you keep a reference, you can use isDeleted to check that it's safe to access the model's data.

readonly namestring

The primary cell value in this record, formatted as a string.

console.log(myRecord.name);
// => '42'
readonly urlstring

The URL for the record. You can visit this URL in the browser to be taken to the record in the Airtable UI.

console.log(myRecord.url);
// => 'https://airtable.com/appxxxxxxxxxxxxxx/tblxxxxxxxxxxxxxx/recxxxxxxxxxxxxxx'
getAttachmentClientUrlFromCellValueUrl
function (attachmentId: string, attachmentUrl: string) => string
attachmentId

The ID of the attachment.

attachmentUrl

The attachment's URL (which is not suitable for rendering on the client).

Returns a URL that is suitable for rendering an attachment on the current client. The URL that is returned will only work for the current user.

import React from 'react';
function RecordAttachments(props) {
const {record, attachmentField} = props;
const attachmentCellValue = record.getCellValue(attachmentField);
if (attachmentCellValue === null) {
return null;
}
return (
<div>
{attachmentCellValue.map(attachmentObj => {
const clientUrl =
record.getAttachmentClientUrlFromCellValueUrl(
attachmentObj.id,
attachmentObj.url
);
return (
<img key={attachmentObj.id} src={clientUrl} width={200} />
);
})}
</div>
);
}
getCellValue
function (fieldOrFieldIdOrFieldName: Field | FieldId | string) => unknown
fieldOrFieldIdOrFieldName

The field (or field ID or field name) whose cell value you'd like to get.

Gets the cell value of the given field for this record.

const cellValue = myRecord.getCellValue(mySingleLineTextField);
console.log(cellValue);
// => 'cell value'
getCellValueAsString
function (fieldOrFieldIdOrFieldName: Field | FieldId | string) => string
fieldOrFieldIdOrFieldName

The field (or field ID or field name) whose cell value you'd like to get.

Gets the cell value of the given field for this record, formatted as a string.

const stringValue = myRecord.getCellValueAsString(myNumberField);
console.log(stringValue);
// => '42'
getColorHexInView
function (viewOrViewIdOrViewName: View | string) => string | null
viewOrViewIdOrViewName

The view (or view ID or view name) to use for record coloring.

Gets the CSS hex string for this record in a given view, or null if the record has no color in that view.

Can be watched with the 'colorInView:${ViewId}' key.

getColorInView
function (viewOrViewIdOrViewName: View | ViewId | string) => Color | null
viewOrViewIdOrViewName

The view (or view ID or view name) to use for record coloring.

Gets the color of this record in a given view, or null if the record has no color in that view.

Can be watched with the 'colorInView:${ViewId}' key.

selectLinkedRecordsFromCell
function (fieldOrFieldIdOrFieldName: Field | FieldId | string, opts: RecordQueryResultOpts = {}) => LinkedRecordsQueryResult
fieldOrFieldIdOrFieldName

The multipleRecordLinks field (or field ID or field name) to use.

opts

Options for the query, such as sorts and fields.

Select records referenced in a multipleRecordLinks cell value. Returns a query result containing the records in the given multipleRecordLinks field. See RecordQueryResult for more.

selectLinkedRecordsFromCellAsync
function (fieldOrFieldIdOrFieldName: Field | FieldId | string, opts: RecordQueryResultOpts = {}) => Promise<LinkedRecordsQueryResult>
fieldOrFieldIdOrFieldName

The multipleRecordLinks field (or field ID or field name) to use.

opts

Options for the query, such as sorts and fields.

Select and load records referenced in a multipleRecordLinks cell value. Returns a query result promise containing the records in the given multipleRecordLinks field. See RecordQueryResult for more.

Remember to call queryResult.unloadData once you're finished with the query.

toString
function () => string

A string representation of the model for use in debugging.

unwatch
function (keys: WatchableRecordKey | ReadonlyArray<WatchableRecordKey>, callback: function (model: this, key: WatchableRecordKey, args: ...Array<any>) => unknown, context?: FlowAnyObject | null) => Array<WatchableRecordKey>
keys

the keys to unwatch

callback

the function passed to .watch for these keys

context

the context that was passed to .watch for this callback

Unwatch keys watched with .watch.

Should be called with the same arguments given to .watch.

Returns the array of keys that were unwatched.

watch
function (keys: WatchableRecordKey | ReadonlyArray<WatchableRecordKey>, callback: function (model: this, key: WatchableRecordKey, args: ...Array<any>) => unknown, context?: FlowAnyObject | null) => Array<WatchableRecordKey>
keys

the keys to watch

callback

a function to call when those keys change

context

an optional context for this in callback.

Get notified of changes to the model.

Every call to .watch should have a matching call to .unwatch.

Returns the array of keys that were watched.