Skip to main content

Custom Table

A sub namespace of Document, exclusive for custom table operations.

Namespace: SW.Document.CustomTable


get

Description

Fetches all rows from a custom table and returns them as flat JavaScript objects (column names as keys). Optionally sorts the result by a column on the client side.

Method(s)

declare function get(
customTableName: string,
orderByColumnName?: string
): Promise<object[]>
ParameterTypeRequiredDefaultsDescription
customTableNamestringtrueName of the custom table
orderByColumnNamestringfalsenullColumn name to sort the results by (client-side)

Basic Usage

// Get all rows from the "ProductCatalog" table
const rows = await SW.Document.CustomTable.get("ProductCatalog");

// Get rows sorted by "Name"
const sorted = await SW.Document.CustomTable.get("ProductCatalog", "Name");

create

Description

Creates a new custom table definition, or adds columns to an existing table. Defines the key column and the schema (column names and data types).

Method(s)

declare function create(
customTableName: string,
model: CustomTablePostModel
): Promise<any>
ParameterTypeRequiredDefaultsDescription
customTableNamestringtrueName of the custom table to create
modelCustomTablePostModeltrueTable definition including key column and columns

CustomTablePostModel

PropertyTypeRequiredDescription
KeyColumnNamestringtrueName of the primary key column (e.g. "Oid")
KeyDataTypeIdnumberfalseData type of the key column (see Data Types table below)
ColumnsCustomTableColumnPostModel[]trueArray of column definitions

Basic Usage

await SW.Document.CustomTable.create("ProductCatalog", {
KeyColumnName: "Oid",
KeyDataTypeId: 9, // UniqueIdentifier
Columns: [
{ ColumnName: "Name", ColumnDataTypeId: 6 }, // Varchar100
{ ColumnName: "Price", ColumnDataTypeId: 4 }, // Money
{ ColumnName: "IsActive", ColumnDataTypeId: 0 }, // Boolean
]
});

insert

Description

Inserts or updates one or more rows in a custom table. Accepts a single row or an array of rows. Each row defines its key and column values.

Method(s)

declare function insert(
customTableName: string,
rows: CustomTableRowPostModel | CustomTableRowPostModel[]
): Promise<any[]>
ParameterTypeRequiredDefaultsDescription
customTableNamestringtrueName of the custom table
rowsCustomTableRowPostModel | CustomTableRowPostModel[]trueOne row or an array of rows to insert/update

CustomTableRowPostModel

PropertyTypeRequiredDescription
KeyValueanyfalseValue of the key column for this row (e.g. a GUID)
KeyColumnNamestringfalseName of the key column (e.g. "Oid")
ColumnsCustomTableRowColumnPostModel[]trueArray of column name/value pairs for this row

CustomTableRowColumnPostModel

PropertyTypeRequiredDescription
ColumnNamestringtrueColumn name
ColumnDataTypeIdnumberfalseData type ID (see Data Types table)
ValueanytrueThe value to store

Basic Usage

// Insert a single row
await SW.Document.CustomTable.insert("ProductCatalog", {
KeyValue: SW.Utils.Guid.getNew(),
KeyColumnName: "Oid",
Columns: [
{ ColumnName: "Name", ColumnDataTypeId: 6, Value: "Widget A" },
{ ColumnName: "Price", ColumnDataTypeId: 4, Value: 29.99 },
{ ColumnName: "IsActive", ColumnDataTypeId: 0, Value: true },
]
});

// Insert multiple rows at once
await SW.Document.CustomTable.insert("ProductCatalog", [
{
KeyValue: SW.Utils.Guid.getNew(),
KeyColumnName: "Oid",
Columns: [
{ ColumnName: "Name", Value: "Widget A" },
{ ColumnName: "Price", Value: 29.99 },
]
},
{
KeyValue: SW.Utils.Guid.getNew(),
KeyColumnName: "Oid",
Columns: [
{ ColumnName: "Name", Value: "Widget B" },
{ ColumnName: "Price", Value: 49.99 },
]
}
]);

Data Types Reference

Each column has a ColumnDataTypeId that defines the SQL data type used for storage.

IDTypeDescription
0BooleanTrue / False
1DateDate value
2FloatDecimal number
3IntegerWhole number
4MoneyCurrency value
5Varchar50Text (max 50 chars)
6Varchar100Text (max 100 chars)
7VarcharMaxText (unlimited)
8TextLarge text
9UniqueIdentifierGUID / UUID
10Varchar200Text (max 200 chars)