GlideDynamicAttributeStore - Global

  • Release version: Yokohama
  • Updated January 30, 2025
  • 10 minutes to read
  • The GlideDynamicAttributeStore API provides access to a dynamic attribute store data type, similar to other data types such as string, date, or date/time.

    This API provides methods that enable you to get and set dynamic schema attributes within a GlideDynamicAttribute object. These dynamic attributes enable each row in a table to contain different fields. The fields on which this data type is applied are shown as dynamic_attribute_store within the column data type description of the table. For more details on dynamic attributes, see Dynamic schema.

    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.

    The following screenshot shows the dynamic attribute group and associated dynamic attributes that are used in the code examples for this API. The defined attributes provide an example of each of the data types that the dynamic schema implementation supports.
    Dynamic attribute group setup

    There are methods in this API that have the same functionality as dynamic schema methods in the GlideRecord API. Use this API if you want to set the same group of dynamic attributes on multiple records. Using this API, you can stage a GlideDynamicAttributeStore object with the desired attributes and then copy that object to multiple GlideRecords using the various setDynamicAttributeValues() methods. Using similar dynamic schema methods in the GlideRecord API performs the actions on a specified GlideRecord.

    GlideDynamicAttributeStore - clear()

    Clears all attributes and their values from the GlideDynamicAttributeStore object.

    Table 1. Parameters
    Name Type Description
    None
    Table 2. Returns
    Type Description
    None

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg",24.5234);
    das.setDynamicAttributeValue("cars->total_miles",5324);    
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('das: ' + das.getDisplayValue());
    das.clear();
    gs.info('das: ' + das.getDisplayValue());

    Output:

    *** Script: das: {
      "cars" : {
        "avg_mpg" : "24.5234",
        "color" : "blue",
        "cost" : "12000.5",
        "date_purchased" : "2024-04-19 08:29:52",
        "luxury" : "true",
        "make" : "Toyota",
        "model" : "CRV",
        "total_miles" : "5324"
      }
    }
    *** Script: das: null

    GlideDynamicAttributeStore - getDisplayValue()

    Returns the JSON map representation of the values stored in the current GlideDynamicAttributeStore object.

    This method returns:
    • Boolean values as "true" and "false" instead of 1 and 0.
    • Date/time values in the user’s locale instead of UTC.
    Table 3. Parameters
    Name Type Description
    None
    Table 4. Returns
    Type Description
    String Human-readable JSON map of the values stored in the GlideDynamicAttributeStore object. The contents of this string depends on your dynamic schema definition.

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeValue("cars->total_miles", 5324);
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('Value returned by getValue(): ' + das.getValue());
    gs.info('Value returned by getDisplayValue(): ' + das.getDisplayValue());

    Output:

    *** Script: Value returned by getValue(): {"cars":{"total_miles":5324,"color":"blue","model":"CRV","cost":12000.5,"luxury":1,"avg_mpg":24.5234,"make":"Toyota","date_purchased":"2024-04-19 15:33:23"}}
    *** Script: Value returned by getDisplayValue(): {
      "cars" : {
        "avg_mpg" : "24.5234",
        "color" : "blue",
        "cost" : "12000.5",
        "date_purchased" : "2024-04-19 08:33:23",
        "luxury" : "true",
        "make" : "Toyota",
        "model" : "CRV",
        "total_miles" : "5324"
      }
    }

    GlideDynamicAttributeStore - getDynamicAttributes()

    Returns the set of dynamic attribute definitions present in the store.

    Table 5. Parameters
    Name Type Description
    None
    Table 6. Returns
    Type Description
    Array Array containing all transient and non-transient dynamic attributes present in the store.
    • GlideDynamicAttribute object. Dynamic attributes are defined in the Dynamic Attribute [dynamic_attribute] table with a data type and a sys_id.
    • GlideTransientDynamicAttribute object. Transient dynamic attributes are dynamic attributes that have been added to a DynamicAttributeStore field without a definition in the Dynamic Attribute [dynamic_attribute] table. Transient dynamic attributes are handled as strings and have no sys_id.
    Note:
    The Dynamic Attribute [dynamic_attribute] table is accessible by navigating to All > Dynamic Schema > Dynamic Attribute Groups, selecting a group, and selecting the Dynamic Attributes tab.

    The following example shows how to retrieve transient and non-transient dynamic attributes.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue('a->b', 5);    // transient (adding here)
    das.setDynamicAttributeValue('a->c', 10);   // defined in dynamic_attribute table
    
    var attributes = das.getDynamicAttributes();
    gs.info(attributes);
    
    for (var i = 0; i < attributes.length; i++) {
        var attr = attributes[i];
    	
        gs.info("");
        gs.info("[" + i + "].getPath()      = " + attr.getPath());
        gs.info("[" + i + "].getName()      = " + attr.getName());
        gs.info("[" + i + "].getGroupName() = " + attr.getGroupName());
        gs.info("[" + i + "].getSysId()     = " + attr.getSysId());
        gs.info("[" + i + "].isTransient()  = " + attr.isTransient());
        gs.info("[" + i + "].getType()      = " + attr.getType());
    }

    Output:

    *** Script: a->c,a->b
    *** Script: 
    *** Script: [0].getPath()      = a->c
    *** Script: [0].getName()      = c
    *** Script: [0].getGroupName() = a
    *** Script: [0].getSysId()     = 8bc411a94fc01210b8ddc0e552ce0b3c
    *** Script: [0].isTransient()  = false
    *** Script: [0].getType()      = integer
    *** Script: 
    *** Script: [1].getPath()      = a->b
    *** Script: [1].getName()      = b
    *** Script: [1].getGroupName() = a
    *** Script: [1].getSysId()     = undefined
    *** Script: [1].isTransient()  = true
    *** Script: [1].getType()      = string

    GlideDynamicAttributeStore - getDynamicAttributeValue(String groupAttrPath)

    Returns the value of the specified attribute within the dynamic attribute store element.

    Table 7. Parameters
    Name Type Description
    groupAttrPath 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.

      Table: 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.

      Table: In the Name field of the Dynamic Attribute [dynamic_attribute] table.

    For example: "car->color"

    Table 8. Returns
    Type Description
    Object Value of the dynamic schema attribute referenced by the passed group/attribute path.

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

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeValue("cars->total_miles", 5324);
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('Value returned by getDynamicAttributeValue(): ' + das.getDynamicAttributeValue("cars->color"));
    gs.info('Value returned by getDynamicAttributeValue(): ' + das.getDynamicAttributeValue("cars->luxury"));
    

    Output:

    *** Script: Value returned by getDynamicAttributeValue(): blue
    *** Script: Value returned by getDynamicAttributeValue(): 1

    GlideDynamicAttributeStore - getValue()

    Returns the compact string representation of the contents of the current GlideDynamicAttributeStore object.

    This method returns:
    • Boolean values as 1 and 0 instead of "true" and "false".
    • Date/time values in UTC instead of the user’s locale.
    Table 9. Parameters
    Name Type Description
    None
    Table 10. Returns
    Type Description
    String Compact string representation of the values stored in the GlideDynamicAttributeStore object. The contents of this string depends on your dynamic schema definition.

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeValue("cars->total_miles", 5324);
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('Value returned by getValue(): ' + das.getValue());
    gs.info('Value returned by getDisplayValue(): ' + das.getDisplayValue());

    Output:

    *** Script: Value returned by getValue(): {"cars":{"total_miles":5324,"color":"blue","model":"CRV","cost":12000.5,"luxury":1,"avg_mpg":24.5234,"make":"Toyota","date_purchased":"2024-04-19 15:33:23"}}
    *** Script: Value returned by getDisplayValue(): {
      "cars" : {
        "avg_mpg" : "24.5234",
        "color" : "blue",
        "cost" : "12000.5",
        "date_purchased" : "2024-04-19 08:33:23",
        "luxury" : "true",
        "make" : "Toyota",
        "model" : "CRV",
        "total_miles" : "5324"
      }
    }

    GlideDynamicAttributeStore - setDisplayValue(Object value)

    Clears the current GlideDynamicAttributeStore object and then stores the passed JSON map in the GlideDynamicAttributeStore object.

    This method is functionally the same as GlideDynamicAttributeStore - setValue(Object value), except that it assumes that all date values are provided in the user's locale.

    Table 11. Parameters
    Name Type Description
    value Object Value to set in the current dynamic attribute store object.
    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
    None

    The following example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeValue("cars->total_miles", 5324);    
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('das: ' + das.getDisplayValue());
    das.setDisplayValue('{"cars":{"luxury":false}}');
    gs.info('das: ' + das.getDisplayValue());

    Output:

    *** Script: das: {
      "cars" : {
        "avg_mpg" : "24.5",
        "color" : "blue",
        "cost" : "12000.0",
        "date_purchased" : "2024-04-19 14:16:49",
        "luxury" : "true",
        "make" : "Toyota",
        "model" : "CRV",
        "total_miles" : "5324.0"
      }
    }
    *** Script: das: {
      "cars" : {
        "luxury" : "false"
      }
    }

    GlideDynamicAttributeStore - setDynamicAttributeDisplayValue(String groupAttrPath, Object value)

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

    This method works the same as the GlideDynamicAttributeStore - setDynamicAttributeValue(String groupAttrPath, Object value) method except in its handling of Boolean and date/time values. This method assumes that all date/time values are provided in the user's locale.

    Table 13. Parameters
    Name Type Description
    groupAttrPath 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.

      Table: 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.

      Table: 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 14. Returns
    Type Description
    Object Updated GlideDynamicAttributeStore object.

    If the groupAttrPath parameter isn't valid, the method throws an IllegalArgumentException.

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeDisplayValue("cars->color","blue");
    das.setDynamicAttributeDisplayValue("cars->make","Toyota");
    das.setDynamicAttributeDisplayValue("cars->model","CRV");
    das.setDynamicAttributeDisplayValue("cars->luxury","true");
    das.setDynamicAttributeDisplayValue("cars->cost",12000.5);
    das.setDynamicAttributeDisplayValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeDisplayValue("cars->total_miles", 5324);    
    das.setDynamicAttributeDisplayValue("cars->date_purchased",new GlideDateTime());
    gs.info('das: ' + das.getDisplayValue());
    das.setDisplayValue('{"cars":{"luxury":"false"}}');
    gs.info('das: ' + das.getDisplayValue());

    Output:

    *** Script: das: {
      "cars" : {
        "avg_mpg" : "24.5234",
        "color" : "blue",
        "cost" : "12000.5",
        "date_purchased" : "2024-04-19 10:40:45",
        "luxury" : "true",
        "make" : "Toyota",
        "model" : "CRV",
        "total_miles" : "5324"
      }
    }
    *** Script: das: {
      "cars" : {
        "luxury" : "false"
      }
    }

    GlideDynamicAttributeStore - setDynamicAttributeValue(String groupAttrPath, Object value)

    Sets the dynamic attribute referenced by a specified group/attribute path to a specified value.

    Table 15. Parameters
    Name Type Description
    groupAttrPath 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.

      Table: 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.

      Table: 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 16. Returns
    Type Description
    Object Updated GlideDynamicAttributeStore object.

    If the groupAttrPath parameter isn't valid, the method throws an IllegalArgumentException.

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeValue("cars->total_miles", 5324);
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('Value returned by getValue(): ' + das.getValue());
    gs.info('Value returned by getDisplayValue(): ' + das.getDisplayValue());

    Output:

    *** Script: Value returned by getValue(): {"cars":{"total_miles":5324,"color":"blue","model":"CRV","cost":12000.5,"luxury":1,"avg_mpg":24.5234,"make":"Toyota","date_purchased":"2024-04-19 15:33:23"}}
    *** Script: Value returned by getDisplayValue(): {
      "cars" : {
        "avg_mpg" : "24.5234",
        "color" : "blue",
        "cost" : "12000.5",
        "date_purchased" : "2024-04-19 08:33:23",
        "luxury" : "true",
        "make" : "Toyota",
        "model" : "CRV",
        "total_miles" : "5324"
      }
    }

    GlideDynamicAttributeStore - setDynamicAttributeValues(Object value)

    Sets the internal JSON storage for the field to the String representation of the passed value. If the passed value is another instance of a GlideDynamicAttributeStore object, it copies the values from that object to the current object.

    Table 17. Parameters
    Name Type Description
    value Object JSON object to store as the value in the associated GlideRecord. The method ignores any invalid JSON values.
    Table 18. Returns
    Type Description
    Object Updated GlideDynamicAttributeStore object.

    The following example shows how to store attribute/value pairs in a GlideDynamicAttributeStore object and then copy those same values from one object to another.

    var das = new GlideDynamicAttributeStore();
    var otherValues = new GlideDynamicAttributeStore();
    otherValues.setDynamicAttributeValue("position->x", 5);
    otherValues.setDynamicAttributeValue("position->y", 6);
    
    das.setDynamicAttributeValues(otherValues);
    gs.info(das);

    Output:

    {"_position":{"x":"5.0","y":"6.0"}}

    GlideDynamicAttributeStore - setValue(Object value)

    Clears the current GlideDynamicAttributeStore object and then stores the passed JSON map in that GlideDynamicAttributeStore object.

    This method is functionally the same as GlideDynamicAttributeStore - setDisplayValue(Object value) except that it assumes that all date values are in UTC.

    Table 19. Parameters
    Name Type Description
    value Object JSON map object to store in the GlideDynamicAttributeStore object.

    For example: '{"cars":{"cost":"12500"}}'

    This method ignores any invalid JSON values.
    Table 20. Returns
    Type Description
    None

    The following example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000.5);
    das.setDynamicAttributeValue("cars->avg_mpg", 24.5234);
    das.setDynamicAttributeValue("cars->total_miles", 5324);    
    das.setDynamicAttributeValue("cars->date_purchased", new GlideDateTime());
    gs.info('das: ' + das.getValue());
    das.setValue('{"cars":{"luxury":false}}');
    gs.info('das: ' + das.getValue());

    Output:

    *** Script: das: {"cars":{"total_miles":5324,"color":"blue","model":"CRV","cost":12000.5,"luxury":true,"avg_mpg":24.5234,"make":"Toyota","date_purchased":"2024-04-19 17:28:47"}}
    *** Script: das: {"cars":{"luxury":false}}

    GlideDynamicAttributeStore - toString()

    Returns the content of the GlideDynamicAttributeStore object as a string.

    Table 21. Parameters
    Name Type Description
    None
    Table 22. Returns
    Type Description
    String GlideDynamicAttribute object as a string.

    For example: '{"group":{"attr2":"true","attr1":"42.0"}}'

    The following code example shows how to call this method.

    var das = new GlideDynamicAttributeStore();
    das.setDynamicAttributeValue("cars->color","blue");
    das.setDynamicAttributeValue("cars->make","Toyota");
    das.setDynamicAttributeValue("cars->model","CRV");
    das.setDynamicAttributeValue("cars->luxury",true);
    das.setDynamicAttributeValue("cars->cost",12000);
    das.setDynamicAttributeValue("cars->avg_mpg",24.5);
    das.setDynamicAttributeValue("cars->total_miles",5324);    
    das.setDynamicAttributeValue("cars->date_purchased",new GlideDateTime());
    gs.info('das: ' + das.toString());

    Output:

    *** Script: das: {"cars":{"cost":"12000.0","color":"blue","avg_mpg":"24.5","date_purchased":"2024-04-19 14:05:00","luxury":"true","model":"CRV","make":"Toyota","total_miles":"5324.123"}}