Skip to main content

Datasheet

You can get the datasheet information and support the operation of views, fields and records in the datasheet.

datasheet.Datasheet

Parameters

id

get id(): undefined | string

Datasheet id, unique identification of datasheet

Returns

undefined | string

Example

console.log(myDatasheet.id);
// => 'dstxxxxxxx'

name

get name(): undefined | string

The name of the Datasheet.

Returns

undefined | string

Example

console.log(myDatasheet.name);

description

get description(): undefined | string

Datasheet Description Information

Returns

undefined | string

Example

console.log(myDatasheet.description);

url

get url(): string

Datasheet URL

Returns

string

Example

console.log(myDatasheet.url);

views

get views(): View[]

Datasheet view list

Returns

View[]

Example

console.log(myDatasheet.views);
// => [View, View]

fields

get fields(): undefined | Field[]

All fields of datasheet

Returns

undefined | Field[]

Example

console.log(myDatasheet.fields);
// => [Field, Field]

Methods

getView

getView(viewKey): View

Gets the specified view in the datasheet

Parameters

NameTypeDescription
viewKeystringView name or ID

Returns

View

Example

console.log(myDatasheet.getView('my view')); // => View
console.log(myDatasheet.getView('viwxxxxxx')); // => View

getField

getField(fieldKey): Field

Gets the specified field in the datasheet

Parameters

NameTypeDescription
fieldKeystringField name or ID

Returns

Field

Example

console.log(myDatasheet.getField('a field')); // => Field
console.log(myDatasheet.getField('fldxxxxxx')); // => Field

createFieldAsync

createFieldAsync(name, type, property): Promise<string>

New field

Parameters

NameTypeDescription
namestringField Name
typeFieldTypeField Type
propertyIAddOpenFieldPropertyField Properties

Returns

Promise<string>

Description

For the writing format of the new field attribute value, please refer to FieldType

Example

function createFieldAsync(name, type, property) {
await myDatasheet.createFieldAsync(name, type, property);
}

deleteFieldAsync

deleteFieldAsync(fieldId, conversion?): Promise<void>

Delete field

Parameters

NameTypeDescription
fieldIdstringField ID
conversion?ConversionWhen deleting a field as an associated field, mark whether the associated field of the associated datasheet is deleted or converted to text, the default is Converted to a text field.

Returns

Promise<void>

Description

Throws an error if the user does not have permission to do something.

Example

function deleteFieldAsync(fieldId) {
await myDatasheet.deleteFieldAsync(fieldId);
}

getRecordAsync

getRecordAsync(recordId): Record

Get the specified Record in the datasheet

Parameters

NameTypeDescription
recordIdstringRecord ID

Returns

Record

Example

console.log(myDatasheet.getRecordAsync(myRecordId));
// => Record

getRecordsAsync

getRecordsAsync(options?): Record[]

Bulk fetch Records in Datasheet

Parameters

NameTypeDescription
options?Object-
options.recordIds?string[]Set of record ID
options.sorts?ISortedField[]Records need to be sorted by which fields

Returns

Record[]

Example

console.log(myDatasheet.getRecordsAsync()); // => [Record, Record, ...] console.log(myDatasheet.getRecordsAsync({ recordIds: [myRecordId01, myRecordId02] })); // => [Record, Record]

createRecordAsync

createRecordAsync(valuesMap?, insertPosition?): Promise<string>

Add new record

Parameters

NameTypeDescription
valuesMap{ [key: string]: any; }object mapping fieldId to value for that field.
insertPosition?IInsertPositionposition to insert in view.

Returns

Promise<string>

Returns the new record ID

Description

Adds a new record and optionally specifies its position in the view (default at the end), returning an array of new record IDs.

valuesMap key for fieldId, value for the contents of the cell object, only need to pass to modify the value, do not need to modify the key value do not need to pass. To empty a field, you need to pass key: null.

For cell value writing format, refer to FieldType.

An error will be thrown when the user does not have permission to perform the operation or when the cell value format check does not pass.

Example

async function createNewRecord(valuesMap) {
const newRecordId = await myDatasheet.createRecordAsync(valuesMap);
console.log(`new record ID: ${newRecordId}`);
}

// The key of the parameter is fieldId, and the value is the cell value
createNewRecord({
fld1234567980: 'this is a text value',
fld0987654321: 1024,
});

// Different types of field cell values have specific data structures, which need to be passed in correctly
createNewRecord({
fld1234567890: 'this is a text value', // SingleLineText
fld0987654321: 1024, // Number
fld1234567891: 'option 1', // SingleSelect
fld1234567892: ['option 1', 'option 2'], // MultiSelect
fld1234567893: 1635513510962, // DateTime
fld1234567894: ['rec1234567'], // TwoWayLink (recordId)
});

createRecordsAsync

createRecordsAsync(records?, insertPosition?): Promise<string[]>

the record to update.

Parameters

NameTypeDefault valueDescription
recordsvaluesMap[]object mapping fieldId to value for that field.
insertPosition?IInsertPositionundefinedposition to insert in view.

Returns

Promise<string[]>

Returns an array of added record IDs

Description

Add multiple records and optionally specify its position in the view (inserted at the end by default).

valuesMap in records key for fieldId, value for the contents of the cell object, only need to pass to modify the value, do not need to modify the key value do not need to pass. To empty a field, you need to pass key: null.

For cell value writing format, refer to FieldType.

Example

const records = [
// The key of the item is fieldId, and the value is the cell content
{
fld1234567890: 'this is a text value',
fld0987654321: 1024,
},
// When the item is an empty object, an empty record will be created
{},
// Different types of field cell values have specific data structures, which need to be passed incorrectly
{
fld1234567890: 'Cat video 2', // SingleLineText
fld0987654321: 1024, // Number
fld1234567891: 'option 1', // SingleSelect
fld1234567892: ['option 1', 'option 2'], // MultiSelect
fld1234567893: 1635513510962, // DateTime
fld1234567894: ['rec1234567'], // TwoWayLink (recordId)
},
];

async function createNewRecords() {
const recordIds = await myDatasheet.createRecordsAsync(records);
console.log(`new record IDs: ${recordIds}`);
}

updateRecordAsync

updateRecordAsync(recordId, valuesMap?): Promise<void>

Updates cell values for records.

Parameters

NameTypeDescription
recordIdstringSpecify the records be modified.
valuesMap{ [key: string]: any; }object mapping fieldId to value for that field.

Returns

Promise<void>

Description

Throws an error if the user does not have permission to update the given cell values in the record, recordId does not exist, or when the written value type does not match.

valuesMap key for fieldId, value for the contents of the cell object, only need to pass to modify the value, do not need to modify the key value do not need to pass. To empty a field, you need to pass key: null.

For cell value writing format, refer to FieldType.

If you need to modify multiple records at the same time, use the updateRecordsAsync .

Example

function updateRecordAsync(recordId, valuesMap) {
await myDatasheet.updateRecordAsync(recordId, valuesMap);
}

updateRecordsAsync

updateRecordsAsync(records): Promise<void>

Modify the value of records in batches

Parameters

NameTypeDescription
records{ id: string ; valuesMap: { [key: string]: any; } }[]Specify the records be modified.

Returns

Promise<void>

Description

Throws an error if the user does not have permission to update the given cell values in the record, recordId does not exist, or when the written value type does not match.

valuesMap key for fieldId, value for the contents of the cell object, only need to pass to modify the value, do not need to modify the key value do not need to pass.To empty a field, you need to pass key: null.

We refer to a field in a record as a cell.For cell value writing format, refer to FieldType.

If you only need to modify a single record, use updateRecordAsync

Example

function updateRecordsAsync(id, valuesMap) {
await myDatasheet.updateRecordsAsync([{ id, valuesMap }]);
}

deleteRecordAsync

deleteRecordAsync(recordId): Promise<void>

Delete Record

Parameters

NameTypeDescription
recordIdstringRecord ID

Returns

Promise<void>

Description

Delete a record by recordId.

Throws an error if the user does not have permission to do something.

Example

async function deleteRecordAsync(recordId) {
await myDatasheet.deleteRecordAsync(recordId);
console.log('The record has been deleted');
}

deleteRecordsAsync

deleteRecordsAsync(recordIds): Promise<void>

Bulk delete records

Parameters

NameTypeDescription
recordIdsstring[]array of recordIds.

Returns

Promise<void>

Description

Delete the given record by recordIds.

Throws an error if the user does not have permission to do something.

Example

async function deleteRecordsAsync(recordIds) {
await myDatasheet.deleteRecordsAsync(recordIds);
console.log('Records have been deleted in bulk');
}