# Record

**Kind:** Class

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`.

## Properties

### `commentCount`

Type: `number`

The number of comments on this record.

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

### `createdTime`

Type: `Date`

The created time of this record.

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

### `id`

Type: `string`

The ID for this model.

### `isDeleted`

Type: `boolean`

`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.

### `name`

Type: `string`

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

```js
console.log(myRecord.name);
// => '42'
```

### `url`

Type: `string`

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

```js
console.log(myRecord.url);
// => 'https://airtable.com/appxxxxxxxxxxxxxx/tblxxxxxxxxxxxxxx/recxxxxxxxxxxxxxx'
```

## Methods

### `getAttachmentClientUrlFromCellValueUrl(attachmentId, attachmentUrl)`

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.

**Parameters:**
- `attachmentId` (`string`) — The ID of the attachment.
- `attachmentUrl` (`string`) — The attachment's URL (which is not suitable for rendering on the client).

**Returns:** `string`

```js
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(fieldOrFieldIdOrFieldName)`

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

**Parameters:**
- `fieldOrFieldIdOrFieldName` (`Field | FieldId | string`) — The field (or field ID or field name) whose cell value you'd like to get.

**Returns:** `unknown`

```js
const cellValue = myRecord.getCellValue(mySingleLineTextField);
console.log(cellValue);
// => 'cell value'
```

### `getCellValueAsString(fieldOrFieldIdOrFieldName)`

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

**Parameters:**
- `fieldOrFieldIdOrFieldName` (`Field | FieldId | string`) — The field (or field ID or field name) whose cell value you'd like to get.

**Returns:** `string`

```js
const stringValue = myRecord.getCellValueAsString(myNumberField);
console.log(stringValue);
// => '42'
```

### `getColorHexInView(viewOrViewIdOrViewName)`

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.

**Parameters:**
- `viewOrViewIdOrViewName` (`View | string`) — The view (or view ID or view name) to use for record coloring.

**Returns:** `string | null`

### `getColorInView(viewOrViewIdOrViewName)`

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.

**Parameters:**
- `viewOrViewIdOrViewName` (`View | ViewId | string`) — The view (or view ID or view name) to use for record coloring.

**Returns:** `Color | null`

### `selectLinkedRecordsFromCell(fieldOrFieldIdOrFieldName, opts)`

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

**Parameters:**
- `fieldOrFieldIdOrFieldName` (`Field | FieldId | string`) — The `multipleRecordLinks` field (or field ID or field name) to use.
- `opts` (`RecordQueryResultOpts`) — Options for the query, such as sorts and fields.

**Returns:** `LinkedRecordsQueryResult`

### `selectLinkedRecordsFromCellAsync(fieldOrFieldIdOrFieldName, opts)`

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.

**Parameters:**
- `fieldOrFieldIdOrFieldName` (`Field | FieldId | string`) — The `multipleRecordLinks` field (or field ID or field name) to use.
- `opts` (`RecordQueryResultOpts`) — Options for the query, such as sorts and fields.

**Returns:** `Promise<LinkedRecordsQueryResult>`

### `toString()`

A string representation of the model for use in debugging.

**Returns:** `string`

### `unwatch(keys, callback, context?)`

Unwatch keys watched with `.watch`.

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

Returns the array of keys that were unwatched.

**Parameters:**
- `keys` (`WatchableRecordKey | ReadonlyArray<WatchableRecordKey>`) — the keys to unwatch
- `callback` (`object`) — the function passed to `.watch` for these keys
- `context?` (`FlowAnyObject | null`) — the context that was passed to `.watch` for this `callback`

**Returns:** `Array<WatchableRecordKey>`

### `watch(keys, callback, context?)`

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.

**Parameters:**
- `keys` (`WatchableRecordKey | ReadonlyArray<WatchableRecordKey>`) — the keys to watch
- `callback` (`object`) — a function to call when those keys change
- `context?` (`FlowAnyObject | null`) — an optional context for `this` in `callback`.

**Returns:** `Array<WatchableRecordKey>`
