Table API - ServiceNow Fluent
The Table API defines tables [sys_db_object] to store data in an application.
Create a table using the Table object. From the schema property, add Column objects, such as StringColumn or IntegerColumn, to define the columns.
For general information about tables, see Table administration.
Table object
Create a table [sys_db_object] in an application.
| Name | Type | Description |
|---|---|---|
| name | String | Required. A name for the table beginning with the application scope and in all lowercase letters in the following format: <scope>_<name>. The name should match the variable
identifier of the Table object. Note: To add columns to an existing table in a different application scope, you can provide the name of the table without the application scope followed by
as any. The column names must begin with the application scope instead.Maximum length: 80 |
| schema | Array | Required. A list of Column objects. For more information, see Column object. |
| extends | String | The name of any other table on which the table is based. Extending a base table incorporates all the fields of the original table and creates system fields for the new table. If they are in the same scope or if they can be configured from other scopes, you can extend tables that are marked as extensible. |
| label | String or Array | A unique label for the table in list and form views. Field labels can be provided as a string or an array of label objects. For more information, see label object. Maximum length: 80 Default: the value of the name property |
| licensingConfig | Object | The licensing configuration [ua_table_licensing_config] for a table. For more information, see licensingConfig object. |
| display | String | The default display column. Use a column name from the schema property. |
| extensible | Boolean | Flag that indicates whether other tables can extend the table. Valid values:
Changing this property from true to false prevents the creation of additional child tables but existing child tables remain unchanged. Default: false |
| liveFeed | Boolean | Flag that indicates if live feeds are available for records in the table. Valid values:
Default: false |
| accessibleFrom | String | The application scopes that can access the table. Valid values:
Default: public |
| callerAccess | String | The access level for cross-scope requests. Valid values:
For more information, see Restricted caller access privilege settings. Default: none |
| actions | Array | A list of access options. Valid values:
Default: read |
| allowWebServiceAccess | Boolean | Flag that indicates whether web services can make calls to the table. Valid values:
Default: false |
| allowNewFields | Boolean | Flag that indicates whether to allow design time configuration of new fields on the table from other application scopes. Valid values:
Default: false |
| allowUiActions | Boolean | Flag that indicates whether to allow design time configuration of UI actions on the table from other application scopes. Valid values:
Default: false |
| allowClientScripts | Boolean | Flag that indicates whether to allow design time configuration of client scripts on the table from other application scopes. Valid values:
Default: false |
| audit | Boolean | Flag that indicates whether to track the creation, update, and deletion of all records in the table. Valid values:
Default: false |
| readOnly | Boolean | Flag that indicates whether users can edit fields in the table. Valid values:
Default: false |
| textIndex | Boolean | Flag that indicates whether search engines index the text in a table. Valid values:
Default: false |
| attributes | Object | Key and value pairs of any supported dictionary attributes [sys_schema_attribute]. For example:For more information, see Dictionary Attributes. |
| index | Array | A list of column references to generate indexes in the metadata XML of the table. The value of the element property should match the object key used with the Column
object. A database index increases the speed of accessing data from the table with the expense of using additional storage. |
| autoNumber | Object | The auto-numbering configuration [sys_number] for a table. For more information, see autoNumber object. |
| scriptableTable | Boolean | Flag that indicates whether the table is a remote table that uses data retrieved from an external source. For more information, see Remote tables. Valid values:
Default: false |
For typeahead support for columns, assign the Table object to an exported variable with the same name as the name property.
import { Table, StringColumn } from "@servicenow/sdk/core";
import { myFunction } from "../server/myFunction.js"
export const x_snc_example_to_do = Table({
name: 'x_snc_example_to_do',
label: 'My To Do Table',
extends: 'task',
schema: {
status: StringColumn({ label: 'Status' }),
deadline: StringColumn({
label: 'Deadline',
active: true,
mandatory: false,
readOnly: false,
maxLength: 40,
dropdown: 'none',
attributes: {
updateSync: false,
},
default: 'today',
dynamicValueDefinitions: {
type: 'calculated_value',
calculatedValue: '',
},
choices: {
choice1: {
label: 'Choice1 Label',
sequence: 0,
inactiveOnUpdate: false,
dependentValue: '5',
hint: 'hint',
inactive: false,
language: 'en',
},
choice2: { label: 'Choice2 Label', sequence: 1 },
},
}),
dynamic1: StringColumn({
dynamicValueDefinitions: {
type: 'calculated_value',
calculatedValue: myFunction,
},
}),
dynamic2: StringColumn({
dynamicValueDefinitions: {
type: 'dynamic_default',
dynamicDefault: `gs.info()`,
},
}),
dynamic3: StringColumn({
dynamicValueDefinitions: {
type: 'dependent_field',
columnName: 'status',
},
}),
dynamic4: StringColumn({
dynamicValueDefinitions: {
type: 'choices_from_other_table',
table: 'sc_cat_item',
field: 'display',
},
}),
},
actions: ['create', 'read'],
display: 'deadline',
accessibleFrom: 'package_private',
allowClientScripts: true,
allowNewFields: true,
allowUiActions: true,
allowWebServiceAccess: true,
extensible: true,
liveFeed: true,
callerAccess: 'none',
autoNumber: {
number: 10,
numberOfDigits: 2,
prefix: 'abc',
},
audit: true,
readOnly: true,
textIndex: true,
attributes: {
updateSync: true,
},
index: [
{
name: 'idx',
element: 'status',
unique: true,
},
],
})
Column object
Add a column [sys_dictionary] to a table.
Add Column objects in the schema property of the Table object.
There are many types of columns based on the field type. Column objects use the format <Type>Column where <Type> is the field type. For information about field types, see Field types reference.
The following types of columns are supported: ListColumn, RadioColumn, StringColumn, ChoiceColumn, ScriptColumn, BooleanColumn, ConditionsColumn, DecimalColumn, IntegerColumn, VersionColumn, DomainIdColumn, FieldNameColumn, ReferenceColumn, TableNameColumn, UserRolesColumn, BasicImageColumn, DocumentIdColumn, DomainPathColumn, TranslatedTextColumn, SystemClassNameColumn, TranslatedFieldColumn, GenericColumn, DateColumn, DateTimeColumn, CalendarDateTime, BasicDateTimeColumn, DueDateColumn, CalendarDateTime, IntegerDateColumn, ScheduleDateTimeColumn, OtherDateColumn, Password2Column, GuidColumn, JsonColumn, NameValuePairsColumn, UrlColumn, EmailColumn, HTMLColumn, FloatColumn, MultiLineTextColumn, DurationColumn, TimeColumn, FieldListColumn, SlushBucketColumn, TemplateValueColumn, and ApprovalRulesColumn.
| Name | Type | Description |
|---|---|---|
| label | String or Array | A unique label for the column that appears on list headers and form fields. Field labels can be provided as a string or an array of label objects. For more information, see label object. Default: the key used for the column object |
| maxLength | Number | The maximum length of values in the column. A length of under 254 appears as a single-line text field. Anything 255 characters or over appears as a multi-line text box. Note: To avoid data loss, only decrease the length of a string field when you’re developing a new application and not when a field contains data. Default: varies depending on the column type |
| active | Boolean | Flag that indicates whether to display the field in lists and forms. Valid values:
Default: true |
| mandatory | Boolean | Flag that indicates whether the field must contain a value to save a record. Valid values:
Default: false |
| readOnly | Boolean | Flag that indicates whether you can edit the field value. Valid values:
Default: false |
| readOnlyOption | String | Control the ability to edit read-only fields by configuring read-only options. Valid values:
For more information, see Configuring read-only security options. |
| default | Any | The default value of the field when creating a record. The value must use the correct type based on the column type. |
| choices | Object | A list of choices [sys_choice] for a column. For more information, see choices object. This property only applies to ChoiceColumn objects and column types that extend choice columns. It can include either an array of primitive values or a series of choice objects. |
| attributes | Object | Key and value pairs of any supported dictionary attributes [sys_schema_attribute]. For example:For more information, see Dictionary Attributes. |
| functionDefinition | String | The definition of a function that the field performs, such as a mathematical operation, field length computation, or day of the week calculation. Each definition begins with For example, the following function definition creates a field that shows the short description, followed by a space, followed by the caller
name: For more information about function definitions, see Function field. |
| dynamicValueDefinitions | Object | Default values that are generated dynamically based on dynamic filters. Provide a combination of a type and a related behavior key to specify dynamic defaults. The following types are supported:
|
| dropdown | String | An option for how a list of choices displays for list and form views of the table. This property only applies to ChoiceColumn objects and column types that extend choice columns. Valid values:
Default: none |
schema: {
deadline: DateColumn({ label: 'Deadline' }),
state: StringColumn({
label: 'State',
choices: {
ready: { label: 'Ready' },
completed: { label: 'Completed' },
inProgress: { label: 'In Progress' },
}
}),
task: StringColumn({ label: 'Task', maxLength: 120 }),
}schema: {
x_scope_myColumn: StringColumn({...})
}choices object
Configure choices [sys_choice] for a column in a table.
The choices object is a property within the Column object. Use the choices object with supported column types in the schema property of a Table object. Only certain column types extend the choice column type (ChoiceColumn) and can include choices.
| Name | Type | Description |
|---|---|---|
| label | String | Required. The text to display for the choice in the list. |
| dependentValue | String | A value that you map to the dependentField in the dynamicValueDefinitions property of the Column object. |
| hint | String | A short description of the choice that displays as tooltip when hovering over it. |
| language | String | The BCP 47 code of the language for the translated choice. Default: en |
| sequence | Integer | The order in the list of choices that a choice occurs. |
| inactive | Boolean | Flag that indicates whether to show the choice in the list. Valid values:
Default: false |
The choices object includes a series of choice objects, where the names of the choices are provided as object keys paired with the choices definitions.
choices: {
choice1: {
label: 'Choice1 Label',
sequence: 0,
inactiveOnUpdate: false,
dependentValue: '5',
hint: 'hint',
inactive: false,
language: 'en',
},
choice2: { label: 'Choice2 Label', sequence: 1 },
}
label object
Configure a field label [sys_documentation] for a table or column.
The label object is a property within the Table and Column objects.
| Name | Type | Description |
|---|---|---|
| language | String | The BCP 47 code of the language for the field label. A language can have only one label, so each language must be unique within an array of label objects. |
| label | String | The text of the field label in the specified language. |
| hint | String | A short description that displays as a tooltip when hovering over the field label. |
| help | String | Additional information about the field. Help text isn’t displayed in form or list views of the table. |
| plural | String | The plural form of the field label. |
| url | String | A URL for a web page that provides information about the field. When a URL is provided, the label displays as a hyperlink. |
| urlTarget | String | Not used (deprecated). |
label: [
{
label: 'English description',
language: 'en',
hint: 'Provide a short description'
},
{
label: 'Description de español',
language: 'es'
},
]
licensingConfig object
Create a licensing configuration [ua_table_licensing_config] to track subscription counts for a table.
The licensingConfig object is a property within the Table object. If this property isn’t specified, a default licensing configuration with licenseModel set to none is generated for the table on the instance.
| Name | Type | Description |
|---|---|---|
| licenseModel | String | The model for tracking subscription usage. Valid values:
Default: none |
| licenseRoles | Array | A list of roles for which any operations on records in the table count toward the subscription. |
| opDelete | Boolean | Flag that indicates whether a subscription is required to delete records for tables with the producer model. Valid values:
Default: true |
| opInsert | Boolean | Flag that indicates whether a subscription is required to insert records for tables with the producer model. Valid values:
Default: true |
| opUpdate | Boolean | Flag that indicates whether a subscription is required to update records for tables with the producer model.
Default: true |
| licenseCondition | String | A filter query that determines conditions for counting operations toward a subscription. For the fulfiller model, specify the set of conditions that determine whether the logged-in user is the fulfiller of the record. For the producer model, specify the set of conditions that determine whether records count toward the subscription. |
| ownerCondition | String | A filter query that determines whether a user owns a record for the fulfiller model. |
| isFulfillment | Boolean | Not used (deprecated). Flag that indicates whether to disallow updates by users who aren't subscribed to the application. Valid values:
Default: false |
licensingConfig: {
licenseModel: 'fulfiller',
opInsert: false,
licenseRoles: ['admin'],
}
autoNumber object
Configure auto-numbering [sys_number] for a table.
The autoNumber object is a property within the Table object. To use the number in a table, you must create a number column, such as IntegerColumn, that uses the number as the default value.
| Name | Type | Description |
|---|---|---|
| prefix | String | A prefix for every record number in the table. For example, INC for Incident. Default: pre |
| number | Integer | The base record number for this table. Record numbers are automatically incremented, and the next number is maintained in the Counter [sys_number_counter] table. If you set the base number to a value higher than the current counter, the next record number uses the new base number. Otherwise the next record number uses the current counter. The counter doesn’t reset to a base number lower than itself. Default: 1000 |
| numberOfDigits | Integer | The minimum number of digits to use after the prefix. Leading zeros are added to auto-numbers, if necessary. For example, INC0001001 contains three leading zeros. The number of digits can exceed the minimum length. For example, if numberOfDigits is 2 and more than 99 records are created on the table, the numbers continue past 100 (such as INC101). Warning: Changing this field can update all number values for existing records on a table. Take care when changing this field on a production instance. Default: 7 |
autoNumber: {
prefix: 'TODO',
number: 2000,
numberOfDigits: 9,
}
number: IntegerColumn({
default: 'javascript:getNextObjNumberPadded();'
})