Dynamic Schema
Summarize
Summary of Dynamic Schema
Dynamic Schema in ServiceNow allows you to define and organize metadata through a hierarchy of categories, groups, and attributes. This flexible schema approach lets you capture different sets of attributes dynamically for each record without adding new columns to tables. It enables you to efficiently manage and store attribute-value pairs that describe diverse data types within a single table.
Show less
Key Features
- Flexible Metadata Organization: Create structured hierarchies of dynamic categories, attribute groups, and attributes to adapt to varied data requirements.
- Dynamic Attribute Storage: Store multiple attribute-value pairs as string objects within a dynamic attribute store field on records.
- Dynamic Attribute Management APIs: Use global APIs such as DynamicSchemaAPI, GlideRecord, GlideAggregate, and GlideDynamicAttributeStore to access, query, and manipulate dynamic attributes programmatically.
- Dynamic Choice Sets: Define fixed sets of values for attributes and manage these choices dynamically.
- Record-Level Flexibility: Capture transient and persistent dynamic attributes on records using GlideRecord methods like setValue() and setDynamicAttributeValue().
Practical Use Case
For example, in a custom Products table, you can define attribute groups for different product types such as electronics or clothing, with attributes like screen type or size. These groups can be organized into categories like electronics or home goods. Users can then add records that capture unique attribute sets per product, enabling detailed and flexible product descriptions without altering the table schema.
Implementation Steps
- Plan your metadata strategy by deciding on categories, groups, and attributes.
- Create dynamic attribute groups and add relevant dynamic attributes to each group.
- Organize groups into dynamic categories for better structure.
- Add dynamic attribute store fields to your tables to hold the attribute data.
- Populate these fields using GlideRecord methods, enabling dynamic data capture on records.
Benefits for ServiceNow Customers
- Eliminates the need for adding columns to tables, simplifying schema management.
- Enables flexible data capture tailored to diverse record types within a single table.
- Provides comprehensive APIs for integration and automation around dynamic attributes.
- Improves data organization and retrieval through structured metadata hierarchies.
Define a hierarchy of categories, groups, and attributes and enable users to select groups of attributes on a record.
Key benefits
- Organize and define metadata in flexible schema instead of adding new columns to a table.
- Define a structured framework for grouping dynamic attributes.
- Capture data dynamically using different attributes per record.
Dynamic schema workflow
- Plan your metadata strategy.
- Create groups of attributes.
- Add dynamic attributes to each group.
- Organize your groups into categories.
- Add dynamic attribute store fields to your tables.
- Populate dynamic attribute store fields using the GlideRecord setValue() method.
Use cases
- Capture groups of 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 groups of dynamic attributes for each type of product (like screen type, UPC, color, or size). You can organize the groups 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 dynamic attribute-value pairs as string objects in a dynamic attribute store field. You can also capture transient attribute-value pairs 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
- DynamicSchemaAPI - Global
- GlideAggregate - Global
Only the following GlideAggregate methods support the usage of dynamic attributes:
- GlideAggregate - addAggregate(String agg, String name)
- GlideAggregate - addHaving(String aggName, String fieldName, String operator, String value)
- GlideAggregate - getDynamicAttributeValue(String fullPath)
- GlideAggregate - getDynamicAttributeValue(String dynamicAttributeField, String groupAttrPath)
- GlideAggregate - getDynamicAttributeDisplayValue(String fullPath)
- GlideAggregate - getDynamicAttributeDisplayValue(String dynamicAttributeField, String groupAttrPath)
- GlideAggregate - getValue(String name)
- GlideAggregate - groupBy(String name)
- GlideAggregate - orderBy(String name)
- GlideAggregate - orderByAggregate(String agg, String fieldName)
- GlideDynamicAttributeStore - Global
- GlideElementDynamicAttributeStore - Global
- GlideRecord - Global
Only the following GlideRecord methods support dynamic attributes:
- GlideRecord - addQuery(String name, Object operator, Object value)
- GlideRecord - getDisplayValue(String name)
- GlideRecord - getDynamicAttribute(String fullPath)
- GlideRecord - getDynamicAttribute(String dynamicAttributeField, String groupAttrPath)
- GlideRecord - getDynamicAttributeDisplayValue(String fullPath)
- GlideRecord - getDynamicAttributeDisplayValue(String dynamicAttributeField, String groupAttrPath)
- GlideRecord - getDynamicAttributeValue(String fullPath)
- GlideRecord - getDynamicAttributeValue(String dynamicAttributeField, String groupAttrPath)
- GlideRecord - getValue(String fieldName)
- GlideRecord - orderBy(String fieldName)
- GlideRecord - orderByDesc(String fieldName)
- GlideRecord - setDisplayValue(String name, Object value)
- GlideRecord - setDynamicAttributeDisplayValue(String fullPath, Object value)
- GlideRecord - setDynamicAttributeDisplayValue(String dynamicAttributeField, String groupAttrPath, Object value)
- GlideRecord - setDynamicAttributeValue(String fullPath, Object value)
- GlideRecord - setDynamicAttributeValue(String dynamicAttributeField, String groupAttrPath, Object value)
- GlideRecord - setDynamicAttributeValues(String dynamicAttributeField, GlideDynamicAttributeStore values)
- GlideRecord - setValue(String name, Object value)