Tables, Columns, and Relationships Guide
Guide for creating ServiceNow Tables (sys_db_object), Columns (sys_dictionary), and Relationships (sys_relationship) to define data models. Use when the user mentions tables, columns, fields, schema, extending tables, relationships, related lists, or data modeling.
When to Use
- When creating new tables to store application data
- When adding columns (fields) to new or existing tables
- When extending an existing table (e.g., extending
task) - When setting up relationships between tables or configuring related lists
- When defining choices, defaults, or dynamic values for fields
For field enforcement rules: Use column properties (mandatory, readOnly) for unconditional rules that always apply. For conditional enforcement, choose based on where the rule applies:
- Data policies — server-side enforcement on both UI and API, applies regardless of how the record is created/updated. See the
data-policy-guidetopic. - UI policies — client-side enforcement in forms only, for dynamic field visibility, mandatory, and read-only rules based on form state.
- Business rules — server-side logic for complex validation, field calculations, or enforcement that requires scripting beyond simple mandatory/read-only rules. See the
business-rule-guidetopic.
For automatic field population: Use column default for static, unconditional defaults. For conditional population based on other field values, choose based on the mechanism:
- Data Lookup — deterministic, no-script field population: "when field X is Y, set field Z to A". Values are maintained as data rows in a matcher table. See the
data-lookup-guidetopic. - Assignment rules — automatic population of
assignment_grouporassigned_toon task-inherited tables. See theassignment-rule-guidetopic. - Business rules — scripted field population requiring calculations, external API calls, or logic beyond simple field matching. See the
business-rule-guidetopic.
Key Concepts
- Tables define the data model. Columns define the fields. Relationships connect tables and display related records as lists on forms.
- Implicit vs explicit relationships: If a reference field exists between tables, the relationship is implicit (no extra record needed). If not, create an explicit
sys_relationshiprecord. - To access the table using the Table API,
allowWebServiceAccessmust be enabled.
Instructions
Creating a New Table
- Table naming: The name must start with the application scope prefix (e.g.,
x_acme_my_table). The exported variable name MUST match thenameproperty exactly. - Choose column types carefully: Only use supported column types. Only import the types you use to avoid build errors.
- Extending tables: Use the
extendsproperty to inherit all fields from a base table. Only extend tables marked as extensible. - Cross-scope access: Set
accessibleFrom,callerAccess, andactionsbased on whether other scoped apps need access. - Enable web service access: If the table will be accessed via the Table API (
/api/now/table) or any REST integration, setallowWebServiceAccess: true. This defaults tofalse-- without it, REST calls return 403 "User Not Authorized" even when ACLs are correctly configured.
Field and Table Naming Conventions
Table and column names must follow ServiceNow's scope-based naming rules. These are enforced by the build — the table plugin emits diagnostics (errors) when they are violated, so a non-conforming name fails the build rather than silently misbehaving. Table names are limited to max length of 30.
Character rules (all scopes)
- Table name — lowercase letters, numbers, and underscores only, and must end with a letter or number (not an underscore). Violation: "Table name must only contain lowercase letters, numbers, and underscores and end with a letter or number."
- Column name — lowercase letters, numbers, and underscores only. Violation: "Column name must only contain lowercase letters, numbers, and underscores."