Dynamic Schema
Summarize
Summary of Dynamic Schema
Dynamic Schema in the Zurich release enables ServiceNow customers to define a flexible hierarchy of categories and attributes to describe records dynamically. Instead of adding static columns to tables, it allows capturing metadata through dynamic attributes organized within dynamic categories. This approach supports diverse data capture needs across different records and tables without structural changes to the database schema.
Show less
Key Features
- Dynamic Attributes: These are name-value pairs describing a record. They can be defined formally or created transiently on the fly within a dynamic attribute store field.
- Dynamic Categories: Containers that organize dynamic attributes into a hierarchy, allowing inheritance of attributes from parent categories.
- Dynamic Attribute Store: A specialized field type that stores one or more dynamic attributes and their values. Creating such a field automatically generates an associated dynamic namespace.
- Dynamic Namespace: A scoped collection of dynamic attributes and categories linked to attribute store fields. Multiple fields can share a namespace to facilitate reuse of attribute definitions.
- Flexible Implementation: Attributes can be added transiently without prior definitions or formally defined for enhanced platform support, including specifying data types, choice options, and category organization.
- Reuse and Organization: Dynamic namespaces enable attribute reuse across multiple tables or fields, supporting consistent metadata management.
Use Cases
Dynamic Schema is ideal for scenarios requiring diverse attribute capture per record, such as:
- Describing products with varied characteristics (e.g., electronics, clothing) using dynamic attributes like screen type, color, or size.
- Organizing attributes into logical categories like Electronics, Health and Beauty, or Clothing for better metadata management.
- Capturing transient attributes dynamically at runtime, stored as string values, using APIs like GlideRecord.
APIs and Integration
Dynamic Schema provides global JavaScript APIs to access and manage dynamic attributes programmatically, supporting operations such as querying, setting, and retrieving attribute values. Key APIs include:
- GlideAggregate: Methods to aggregate and query dynamic attributes.
- GlideDynamicAttributeStore, GlideElementDynamicAttributeStore, GlideDynamicNamespace: Core APIs for managing dynamic schema elements.
- GlideRecord: Enhanced methods to get and set dynamic attribute values, query on them, and control their display values.
This API support empowers customers to integrate dynamic schema attributes seamlessly into scripts, queries, and business logic.
Define a hierarchy of categories and enable users to describe a record using one or more attributes.
Key benefits
- Organize and define metadata in a flexible schema instead of adding new columns to a table.
- Capture data dynamically using different attributes per record.
- Define a structured framework of dynamic categories and dynamic attributes.
- Define dynamic categories and dynamic attributes once and reuse them across multiple tables using dynamic namespaces.
Dynamic Schema elements
Dynamic Schema is composed of the following elements.
- Dynamic attributes
- Name-value pairs that describe a record. You can either formally define dynamic attributes or create them on the fly as transient attributes in a dynamic attribute store field.
- Dynamic categories
- Containers for organizing dynamic attributes. A dynamic category can inherit dynamic attributes from its parent category.
- Dynamic attribute store
- A field type for storing one or more dynamic attributes and their values. When you create a dynamic store field, a dynamic namespace is automatically created and associated with that store field.
After creating a store field, you can start storing values for attributes without defining them, or you can specify attribute definitions in the dynamic namespace to take advantage of additional functionality.
- Dynamic namespace
- A scoped collection of dynamic attributes and dynamic categories. Each dynamic attribute store field automatically receives its own dynamic namespace or you can configure multiple dynamic attribute store fields that share a dynamic namespace.
Implementation options
You have flexibility when deciding how to implement Dynamic Schema.
- You can add attributes directly to a dynamic attribute store field without creating formal definitions first. These attributes are considered transient and are treated as having string values in scripts and queries. You can provide a definition for the attribute and modify its type at any time. Modifying the type of an attribute doesn't affect the stored data but changes how the system interacts with that data. See Working with attributes transiently.
- You can take advantage of additional platform support and reuse for attributes by defining them in a dynamic namespace. Defining a dynamic attribute record enables you to specify its type, set choice options, organize it into dynamic categories and more. See Working with Dynamic Schema.
- You can create a dynamic namespace independently. You can add dynamic attributes and dynamic categories to that namespace, and then associate that namespace with one or more dynamic attribute store fields. This enables you to reuse attributes across multiple store fields. See Create a dynamic namespace.
Use cases
- Capture attribute-value pairs that describe products sold in a large department store by defining a dynamic schema for your products. Store the attributes and their data in a dynamic attribute store field.
For example, assume you have a custom Products table that stores records for different types of products like televisions, sunscreens, pillows, and shirts. You can create dynamic attributes for each type of product (like screen type, UPC, color, or size). You can organize the dynamic attributes into dynamic categories (like Electronics, Health and Beauty, Home Goods, and Clothing). Users can add records to your Products table and capture different attributes in each product record.
- Describe a record by capturing one or more transient attributes, with values stored as string objects in a dynamic attribute store field. You can also capture transient attributes on a record by adding a dynamic attribute store field to a table and populating the field with string data using the GlideRecord API.
APIs
- GlideAggregate - Global
The following GlideAggregate methods support the usage of dynamic attributes:
- addAggregate()
- addHaving()
- getDynamicAttributeValue()
- getDynamicAttributeDisplayValue()
- getValue()
- groupBy()
- orderBy()
- orderByAggregate()
- GlideDynamicAttributeStore - Global
- GlideElementDynamicAttributeStore - Global
- GlideDynamicNamespace - Global
- GlideRecord - Global
The following GlideRecord methods support dynamic attributes:
- addQuery()
- getDisplayValue()
- getDynamicAttribute()
- getDynamicAttributeDisplayValue()
- getDynamicAttributeValue()
- getValue()
- orderBy()
- orderByDesc()
- setDisplayValue()
- setDynamicAttributeDisplayValue()
- setDynamicAttributeValue()
- setDynamicAttributeValues()
- setValue()