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[]>
| Parameter | Type | Required | Defaults | Description |
|---|---|---|---|---|
customTableName | string | true | Name of the custom table | |
orderByColumnName | string | false | null | Column 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>
| Parameter | Type | Required | Defaults | Description |
|---|---|---|---|---|
customTableName | string | true | Name of the custom table to create | |
model | CustomTablePostModel | true | Table definition including key column and columns |
CustomTablePostModel
| Property | Type | Required | Description |
|---|---|---|---|
KeyColumnName | string | true | Name of the primary key column (e.g. "Oid") |
KeyDataTypeId | number | false | Data type of the key column (see Data Types table below) |
Columns | CustomTableColumnPostModel[] | true | Array 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[]>
| Parameter | Type | Required | Defaults | Description |
|---|---|---|---|---|
customTableName | string | true | Name of the custom table | |
rows | CustomTableRowPostModel | CustomTableRowPostModel[] | true | One row or an array of rows to insert/update |
CustomTableRowPostModel
| Property | Type | Required | Description |
|---|---|---|---|
KeyValue | any | false | Value of the key column for this row (e.g. a GUID) |
KeyColumnName | string | false | Name of the key column (e.g. "Oid") |
Columns | CustomTableRowColumnPostModel[] | true | Array of column name/value pairs for this row |
CustomTableRowColumnPostModel
| Property | Type | Required | Description |
|---|---|---|---|
ColumnName | string | true | Column name |
ColumnDataTypeId | number | false | Data type ID (see Data Types table) |
Value | any | true | The 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.
| ID | Type | Description |
|---|---|---|
0 | Boolean | True / False |
1 | Date | Date value |
2 | Float | Decimal number |
3 | Integer | Whole number |
4 | Money | Currency value |
5 | Varchar50 | Text (max 50 chars) |
6 | Varchar100 | Text (max 100 chars) |
7 | VarcharMax | Text (unlimited) |
8 | Text | Large text |
9 | UniqueIdentifier | GUID / UUID |
10 | Varchar200 | Text (max 200 chars) |