The GlideElementDynamicAttributeStore API provides convenient script methods for managing dynamic attributes in the current glide record. Use these methods in conjunction with the GlideRecord API to get and set defined dynamic attribute values.

To use this API to create dynamic attributes you must have the dynamic_schema_writer role. To read dynamic data using this API you must have the dynamic_schema_reader role.

This API extends the GlideElement - Global API.

For more information on dynamic attributes, see Dynamic Schema.

GlideElementDynamicAttributeStore - getDynamicAttribute(String attributePath)

Returns a GlideElementDynamicAttribute object representing the dynamic attribute located at the specified dynamic attribute path.

Table 1. Parameters
Name Type Description
attributePath String Attribute path to use to locate the associated dynamic schema attribute.
Format: "group_name->attr_name"
  • group_name: Name of the group that the attribute is associated with. Located in the Name field of the Dynamic Attribute Group [dynamic_attribute_group] table or the Group field of the Dynamic Attribute [dynamic_attribute] table.
  • attr_name: Name of the dynamic attribute within the dynamic group. Located in the Name field of the Dynamic Attribute [dynamic_attribute] table.

For example: "car->color"

Table 2. Returns
Type Description
GlideElementDynamicAttribute Object that contains the specified dynamic attributes.

If the attributePath parameter contains invalid information, returns a null.

Example

The following code example shows how to call this method.

//Gets all the values of the make attribute from the u_inc_dynamic_schema dynamic attribute store column on the incident table
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();
while(gr_Inc.next()) {
    var attr = gr.getDynamicAttribute('inc_dynamic_schema->cars->make');
    gs.info(attr.getValue());
}

//You can also use if(gr_Inc.next()) if you don't want all the values
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();
if(gr_Inc.next()) {
    var attr = gr_Inc.getDynamicAttribute('inc_dynamic_schema->cars->make');
    gs.info(attr.getValue());
}

GlideElementDynamicAttributeStore - getDynamicAttributeDisplayValue(String attributePath)

Returns the display value of the dynamic attribute located at a specified attribute path within a dynamic attribute store. If a display value is not available, it returns the internal value.

Table 3. Parameters
Name Type Description
attributePath String Attribute path to use to locate the associated dynamic schema attribute.
Format: "group_name->attr_name"
  • group_name: Name of the group that the attribute is associated with. Located in the Name field of the Dynamic Attribute Group [dynamic_attribute_group] table or the Group field of the Dynamic Attribute [dynamic_attribute] table.
  • attr_name: Name of the dynamic attribute within the dynamic group. Located in the Name field of the Dynamic Attribute [dynamic_attribute] table.

For example: "car->color"

Table 4. Returns
Type Description
Object Value for the associated dynamic attribute in human-readable format.

If the attributePath parameter contains invalid information, returns a null.

Example

The following code example shows how to call this method.

//Gets all the display values of the luxury attribute from the inc_dynamic_schema dynamic attribute store column on the incident table
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();
while(gr_Inc.next()) {
    var attr = gr_Inc.getDynamicAttributeDisplayValue('inc_dynamic_schema->cars->luxury');
    gs.info(attr);
}

//You can also use if(gr.next()) if you don't want all the values
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();

if(gr_Inc.next()) {
    var attr = gr_Inc.getDynamicAttributeDisplayValue('inc_dynamic_schema->cars->luxury');
    gs.info(attr);
}

GlideElementDynamicAttributeStore - getDynamicAttributeValue(String attributePath)

Returns the internal value of the dynamic attribute pointed to by a passed-in attribute path within a dynamic attribute store.

For more information on dynamic attributes, see Dynamic Schema.

Table 5. Parameters
Name Type Description
attributePath String Attribute path to use to locate the associated dynamic schema attribute.
Format: "group_name->attr_name"
  • group_name: Name of the group that the attribute is associated with. Located in the Name field of the Dynamic Attribute Group [dynamic_attribute_group] table or the Group field of the Dynamic Attribute [dynamic_attribute] table.
  • attr_name: Name of the dynamic attribute within the dynamic group. Located in the Name field of the Dynamic Attribute [dynamic_attribute] table.

For example: "car->color"

Table 6. Returns
Type Description
Object Value of the dynamic attribute pointed to by the passed attribute path.

If the attributePath parameter contains invalid information, returns a null.

Example

The following code example shows how to call this method.

var gr_Inc = new GlideRecord('incident');
gr_Inc.query();

while(gr_Inc.next()) {
    var attr = gr_Inc.getDynamicAttributeValue('inc_dynamic_schema->cars->luxury');
    gs.info(attr);
}
Output:

*** Script: 1

GlideElementDynamicAttributeStore - setDynamicAttributeValue(String attributePath, Object value)

Sets the attribute pointed to by a specified attribute path in a dynamic attribute store to a specified value.

For more information on dynamic attributes, see Dynamic Schema.

Table 7. Parameters
Name Type Description
attributePath String Attribute path to use to locate the associated dynamic schema attribute.
Format: "group_name->attr_name"
  • group_name: Name of the group that the attribute is associated with. Located in the Name field of the Dynamic Attribute Group [dynamic_attribute_group] table or the Group field of the Dynamic Attribute [dynamic_attribute] table.
  • attr_name: Name of the dynamic attribute within the dynamic group. Located in the Name field of the Dynamic Attribute [dynamic_attribute] table.

For example: "car->color"

value Object Value to set in the specified attribute.
Note: For dynamic attributes, only the following data types are supported:
  • Boolean (True/False)
  • Decimal
  • Floating Point Number
  • GlideDate
  • GlideDateTime
  • Integer
  • String
Table 8. Returns
Type Description
GlideElementDynamicAttributeStore Returns a GlideElementDynamicAttributeStore object containing the specified value.

If the groupAttributePath parameter contains invalid information, the attribute is not updated.

Example

The following code example shows how to call this method.

//This simple example inserts a make attribute on the inc_dynamic_schema column where the value of the make attribute is Ford.
var gr_Inc = new GlideRecord('incident');
gr_Inc.setDynamicAttributeValue('inc_dynamic_schema->cars->make', 'Ford');
gr_Inc.insert();

GlideElementDynamicAttributeStore - setDynamicAttributeValues(GlideDynamicAttributeStore values)

Sets the values specified in the passed GlideElementDynamicAttrbuteStore object in the dynamic attribute store of the current GlideRecord element. The current element's data type must be set to Dynamic Attribute Store.

For more information on dynamic attributes, see Dynamic Schema.

Table 9. Parameters
Name Type Description
values GlideDynamicAttributeStore Object that contains the values to set in the current element's dynamic schema. Values not specified in this object are not updated.
Table 10. Returns
Type Description
GlideElementDynamicAttributeStore Updated GlideElementDynamicAttributeStore object.

Example

The following code example shows how to call this method.

var gr_Inc = new GlideRecord('incident');
var das = new GlideDynamicAttributeStore();
das.setDynamicAttributeValue("cars->color", "black");
das.setDynamicAttributeValue("cars->make","Honda");
das.setDynamicAttributeValue("cars->model","CRV");
gr_Inc.setDynamicAttributeValues('inc_dynamic_schema', das);
gr_Inc.insert();

This code example inserts the following in the u_inc_dynamic_schema column:

{
  "cars" : {
    "color" : "black",
    "make" : "Honda",
    "model" : "CRV"
  }
}

GlideElementDynamicAttributeStore - setDynamicAttributeDisplayValue(String attributePath)

Sets the display value of the dynamic attribute located at a specified path within the dynamic attribute store of the current GlideRecord element.

Table 11. Parameters
Name Type Description
attributePath String Attribute path to use to locate the associated dynamic schema attribute.
Format: "group_name->attr_name"
  • group_name: Name of the group that the attribute is associated with. Located in the Name field of the Dynamic Attribute Group [dynamic_attribute_group] table or the Group field of the Dynamic Attribute [dynamic_attribute] table.
  • attr_name: Name of the dynamic attribute within the dynamic group. Located in the Name field of the Dynamic Attribute [dynamic_attribute] table.

For example: "car->color"

value Object Value to set in the current dynamic attribute element.
The passed value must be of one of the following data types:
  • Boolean (True/False)
  • Decimal
  • Floating Point Number
  • GlideDate
  • GlideDateTime
  • Integer
  • String
Table 12. Returns
Type Description
GlideElementDynamicAttributeStore Object that contains the updated glide element.

Example

The following code example shows how to call this method.

var grFleet = new GlideRecord('u_car_fleet');
grFleet.setDynamicAttributeValue('u_dyn_attr_store', 'car->color', 'Yellow');
grFleet.setDynamicAttributeValue('u_dyn_attr_store', 'car->make', 'Ford');
var sysId = grFleet.insert();
gs.info("Inserted: " + grFleet.u_dyn_attr_store);

var daStore = new GlideDynamicAttributeStore();
daStore.setDynamicAttributeValue('car->color', 'Green');
daStore.setDynamicAttributeValue('car->model', 'Bronco');

var geDynAttrStore = grFleet.getElement('u_dyn_attr_store');
geDynAttrStore.setDynamicAttributeDisplayValues(daStore);
grFleet.update();
gs.info("Updated:  " + grFleet.u_dyn_attr_store);

Output:

*** Script: Inserted: {"car":{"color":"Yellow","make":"Ford"}}
*** Script: Updated:  {"car":{"color":"Green","make":"Ford","model":"Bronco"}}

Example

The following code example shows how a Boolean display value is stored as "1" but is passed back as "true".

 var gr_Inc = new GlideRecord('incident');
gr_Inc.setDynamicAttributeDisplayValue('u_inc_dynamic_schema->u_cars->u_luxury', '1');
gr_Inc.insert()

Returned value:

{
  "u_cars" : {
    "u_luxury" : "true"
  }
}

GlideElementDynamicAttributeStore - setDynamicAttributeDisplayValues(GlideDynamicAttributeStore values)

Sets the display values specified in the passed GlideDynamicAttrbuteStore object in the dynamic attributes of the current GlideRecord element. The current element's data type must be set to Dynamic Attribute Store in the associated table.

Table 13. Parameters
Name Type Description
values GlideDynamicAttributeStore Object that contains the display values to set in the current element's dynamic attribute store. Display values not specified in this object are not updated. This object must contain both the attribute path and the display value for each attribute to store.
For example:
{
  "car":{
    "color":"Blue",
    "make":"Ford",
    "model":"Mustang"
  }
}
Table 14. Returns
Type Description
GlideElementDynamicAttributeStore Object that contains the updated glide element.

Example

The following code example shows how to call this method.

var daStore = new GlideDynamicAttributeStore();
daStore.setDynamicAttributeValue('car->make', 'Ford');
daStore.setDynamicAttributeValue('car->model', 'Mustang');
daStore.setDynamicAttributeValue('car->color', 'Blue');
gs.info("daStore: " + daStore);

var gr_Car = new GlideRecord('u_car_fleet');
gr_Car.query();
while(gr_Car.next()) {
  var glideElement = gr_Car.getElement('u_dyn_attr_store');
  glideElement.setDynamicAttributeValues(daStore);
  gr_Car.update();
}