{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":791,"path":"api-reference/server-api-reference/GlideElementDynamicAttStoreAPI.md","title":"GlideElementDynamicAttributeStore - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideElementDynamicAttributeStore- Global\n\nThe 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.\n\nTo 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.\n\nThis API extends the [GlideElement - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementAPI.md) API.\n\nSee also [Dynamic Schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\nSee also:\n\n-   [GlideDynamicAttribute - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttributeAPI.md)\n-   [GlideDynamicNamespace - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicNamespaceAPI.md)\n-   [GlideDynamicAttributeStore - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttStoreAPI.md)\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideElementDynamicAttributeStore - getDynamicAttributeDisplayValue\\(String attributePath\\)\n\nReturns 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.\n\n<table id=\"table_zn3_1md_bbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattributePath\n\n</td><td>\n\nString\n\n</td><td>\n\nAttribute path to use to locate the associated dynamic schema attribute.Format: `\"attr_name\"`\n\n`attr_name`: Name of the dynamic attribute.\n\nTable: In the attribute field of the Dynamic Attribute \\[dynamic\\_attribute\\] table.\n\n</td></tr></tbody>\n</table><table id=\"table_a43_1md_bbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nValue for the associated dynamic attribute in human-readable format.If the **attributePath** parameter contains invalid information, returns a null.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\n//Gets all the display values of the luxury attribute from the inc_dynamic_schema dynamic attribute store column on the incident table\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\nwhile(gr_Inc.next()) {\n    var attr = gr_Inc.getDynamicAttributeDisplayValue('inc_dynamic_schema->luxury');\n    gs.info(attr);\n}\n\n//You can also use if(gr.next()) if you don't want all the values\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\n\nif(gr_Inc.next()) {\n    var attr = gr_Inc.getDynamicAttributeDisplayValue('inc_dynamic_schema->luxury');\n    gs.info(attr);\n}\n```\n\n## GlideElementDynamicAttributeStore - getDynamicAttributePathsInSchema\\(\\)\n\nReturns the set of dynamic attribute paths that are present in the schema configured for the store.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|Array of attribute paths as strings.|\n\nThe following example shows how to return the dynamic attribute paths that are present in the schema and configured for the store.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.get('number', 'INC0009009');\ngs.info(gr_Inc.inc_dynamic_schema.getDynamicAttributePathsInSchema());\n```\n\nOutput:\n\n```\nnumber,short_description,active\n```\n\n## GlideElementDynamicAttributeStore - getDynamicAttributePathsInStore\\(\\)\n\nReturns the set of dynamic attribute paths that are present in the store.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|Array of attribute paths as strings.|\n\nThe following example shows how to return the dynamic attribute paths that are present in the store.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.get('number', 'INC0009009');\ngs.info(gr_Inc.inc_dynamic_schema.getDynamicAttributePathsInStore());\n```\n\nOutput:\n\n```\nseverity,number,opened_at,short_description,urgency,opened_by,impact,active,description,state,priority\n```\n\n## GlideElementDynamicAttributeStore - getDynamicAttributesInStore\\(\\)\n\nReturns the set of dynamic attribute definitions that are present and stored in a field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|Array of [GlideDynamicAttribute](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttributeAPI.md) objects.|\n\nThe following example shows how to retrieve the contents of a stored dynamic attribute, list the attributes it stored, and the attributes in its schema.\n\n```\nvar record = new GlideRecord('cool_thing');\nrecord.get('number', 'COOL0000005');\n\ngs.info(\"Store Contents:\\n\" + JSON.stringify(JSON.parse(record.store1), null, 2) + \"\\n\");\ngs.info(\"Attributes in Store:\\n\" + record.store1.getDynamicAttributesInStore() + \"\\n\");\ngs.info(\"Attributes in Schema:\\n\" + record.store1.getDynamicAttributesInSchema() + \"\\n\");\n```\n\nOutput:\n\n```\n*** Script: Store Contents:\n{\n  {\n    \"b\": \"hello world\"\n  },\n  {\n    \"integer1\": \"5\"\n  },\n  {\n    \"integer1\": \"10\",\n    \"string1\": \"hello\"\n  }\n}\n\n*** Script: Attributes in Store: b,integer1,integer1,string1\n\n*** Script: Attributes in Schema:\ninteger1,string1,integer1\n```\n\n## GlideElementDynamicAttributeStore - getDynamicAttributesInSchema\\(\\)\n\nReturns the set of dynamic attribute definitions that are pointed to in the schema.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|Array of [GlideDynamicAttribute](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttributeAPI.md) objects.|\n\nThe following example shows how to retrieve the contents of a stored dynamic attribute, list the attributes it stored, and the attributes in its schema.\n\n```\nvar record = new GlideRecord('cool_thing');\nrecord.get('number', 'COOL0000005');\n\ngs.info(\"Store Contents:\\n\" + JSON.stringify(JSON.parse(record.store1), null, 2) + \"\\n\");\ngs.info(\"Attributes in Store:\\n\" + record.store1.getDynamicAttributesInStore() + \"\\n\");\ngs.info(\"Attributes in Schema:\\n\" + record.store1.getDynamicAttributesInSchema() + \"\\n\");\n```\n\nOutput:\n\n```\n*** Script: Store Contents:\n{\n  {\n    \"b\": \"hello world\"\n  },\n  {\n    \"integer1\": \"5\"\n  },\n  {\n    \"integer1\": \"10\",\n    \"string1\": \"hello\"\n  }\n}\n\n*** Script: Attributes in Store: b,integer1,integer1,string1\n\n*** Script: Attributes in Schema:\ninteger1,string1,integer1\n```\n\n## GlideElementDynamicAttributeStore - getDynamicAttributeValue\\(String attributePath\\)\n\nReturns the internal value of the dynamic attribute pointed to by a passed-in attribute path within a dynamic attribute store.\n\nSee also [Dynamic Schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\n<table id=\"table_tnp_rld_bbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattributePath\n\n</td><td>\n\nString\n\n</td><td>\n\nAttribute path to use to locate the associated dynamic schema attribute.Format: `\"attr_name\"`\n\n`attr_name`: Name of the dynamic attribute.\n\nTable: In the attribute field of the Dynamic Attribute \\[dynamic\\_attribute\\] table.\n\n</td></tr></tbody>\n</table><table id=\"table_unp_rld_bbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nValue of the dynamic attribute pointed to by the passed attribute path.If the **attributePath** parameter contains invalid information, returns a null.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\n\nwhile(gr_Inc.next()) {\n    var attr = gr_Inc.getDynamicAttributeValue('inc_dynamic_schema->luxury');\n    gs.info(attr);\n}\n```\n\nOutput:\n\n```\n\n*** Script: 1\n```\n\n## GlideElementDynamicAttributeStore - getDynamicNamespace\\(\\)\n\nReturns a dynamic namespace that is configured for the store.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|IDynamicNamespace|Dynamic namespace object information.|\n\nThe following example shows how to return the dynamic namespace object configured for the store.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\nif (gr_Inc.next()) {\n    var namespace = gr_Inc.inc_dynamic_schema.getDynamicNamespace();\n \n    gs.info(\"toString:    \" + namespace);\n    gs.info(\"name:        \" + namespace.getName());\n    gs.info(\"isActive:    \" + namespace.isActive());\n    gs.info(\"isTransient: \" + namespace.isTransient());\n}\n```\n\nOutput:\n\n```\ntoString:    incident/inc_dynamic_schema\nname:        incident/inc_dynamic_schema\nisActive:    true\nisTransient: false\n```\n\n## GlideElementDynamicAttributeStore - getDynamicNamespaceName\\(\\)\n\nGets the name of the dynamic namespace that is configured for the store.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the dynamic namespace.|\n\nThe following example shows how to return the name of the dynamic namespace configured for the store.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\nif (gr_Inc.next()) {\n    gs.info(gr_Inc.inc_dynamic_schema.getDynamicNamespaceName());\n}\n```\n\nOutput:\n\n```\nincident/inc_dynamic_schema\n```\n\n## GlideElementDynamicAttributeStore - setDynamicAttributeValue\\(String attributePath, Object value\\)\n\nSets the attribute pointed to by a specified attribute path in a dynamic attribute store to a specified value.\n\nSee also [Dynamic Schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\n<table id=\"table_aj2_vmd_bbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattributePath\n\n</td><td>\n\nString\n\n</td><td>\n\nAttribute path to use to locate the associated dynamic schema attribute.Format: `\"attr_name\"`\n\n`attr_name`: Name of the dynamic attribute.\n\nTable: In the attribute field of the Dynamic Attribute \\[dynamic\\_attribute\\] table.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td id=\"DynS-value-entry\">\n\nValue to set in the specified attribute.**Note:** For dynamic attributes, only the following data types are supported:\n\n-   Boolean \\(True/False\\)\n-   Decimal\n-   Floating Point Number\n-   GlideDate\n-   GlideDateTime\n-   Integer\n-   String\n\n</td></tr></tbody>\n</table><table id=\"table_bj2_vmd_bbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nGlideElementDynamicAttributeStore\n\n</td><td>\n\nReturns a GlideElementDynamicAttributeStore object containing the specified value.If the **attributePath** parameter contains invalid information, the attribute is not updated.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\n//This simple example inserts a make attribute on the inc_dynamic_schema column where the value of the make attribute is Ford.\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.setDynamicAttributeValue('inc_dynamic_schema->make', 'Ford');\ngr_Inc.insert();\n```\n\n## GlideElementDynamicAttributeStore - setDynamicAttributeValues\\(GlideDynamicAttributeStore values\\)\n\nSets the values specified in the passed GlideElementDynamicAttributeStore object in the dynamic attribute store of the current GlideRecord element. The current element's data type must be set to **Dynamic Attribute Store**.\n\nSee also [Dynamic Schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|values|[GlideDynamicAttributeStore](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttStoreAPI.md)|Object that contains the values to set in the current element's dynamic schema. Values not specified in this object are not updated.|\n\n|Type|Description|\n|----|-----------|\n|GlideElementDynamicAttributeStore|Updated GlideElementDynamicAttributeStore object.|\n\nThe following code example shows how to call this method.\n\n```\nvar gr_Inc = new GlideRecord('incident');\nvar das = new GlideDynamicAttributeStore();\ndas.setDynamicAttributeValue(\"color\", \"black\");\ndas.setDynamicAttributeValue(\"make\",\"Honda\");\ndas.setDynamicAttributeValue(\"model\",\"CRV\");\ngr_Inc.setDynamicAttributeValues('inc_dynamic_schema', das);\ngr_Inc.insert();\n```\n\nThis code example inserts the following in the u\\_inc\\_dynamic\\_schema column:\n\n```\n{\n  \"color\" : \"black\",\n  \"make\" : \"Honda\",\n  \"model\" : \"CRV\"\n}\n```\n\n## GlideElementDynamicAttributeStore - setDynamicAttributeDisplayValue\\(String attributePath\\)\n\nSets the display value of the dynamic attribute located at a specified path within the dynamic attribute store of the current GlideRecord element.\n\n<table id=\"table_bfg_2nd_bbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattributePath\n\n</td><td>\n\nString\n\n</td><td>\n\nAttribute path to use to locate the associated dynamic schema attribute.Format: `\"attr_name\"`\n\n`attr_name`: Name of the dynamic attribute.\n\nTable: In the attribute field of the Dynamic Attribute \\[dynamic\\_attribute\\] table.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue to set in the current dynamic attribute element.The passed value must be of one of the following data types:\n\n-   Boolean \\(True/False\\)\n-   Decimal\n-   Floating Point Number\n-   GlideDate\n-   GlideDateTime\n-   Integer\n-   String\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|GlideElementDynamicAttributeStore|Object that contains the updated glide element.|\n\nThe following code example shows how to call this method.\n\n```\nvar grFleet = new GlideRecord('u_car_fleet');\ngrFleet.setDynamicAttributeValue('u_dyn_attr_store', 'color', 'Yellow');\ngrFleet.setDynamicAttributeValue('u_dyn_attr_store', 'make', 'Ford');\nvar sysId = grFleet.insert();\ngs.info(\"Inserted: \" + grFleet.u_dyn_attr_store);\n\nvar daStore = new GlideDynamicAttributeStore();\ndaStore.setDynamicAttributeValue('color', 'Green');\ndaStore.setDynamicAttributeValue('model', 'Bronco');\n\nvar geDynAttrStore = grFleet.getElement('u_dyn_attr_store');\ngeDynAttrStore.setDynamicAttributeDisplayValues(daStore);\ngrFleet.update();\ngs.info(\"Updated:  \" + grFleet.u_dyn_attr_store);\n```\n\nOutput:\n\n```\n*** Script: Inserted: {\"color\":\"Yellow\",\"make\":\"Ford\"}\n*** Script: Updated:  {\"color\":\"Green\",\"make\":\"Ford\",\"model\":\"Bronco\"}\n```\n\nThe following code example shows how a Boolean display value is stored as \"1\" but is passed back as \"true\".\n\n```\n var gr_Inc = new GlideRecord('incident');\ngr_Inc.setDynamicAttributeDisplayValue('u_inc_dynamic_schema->u_luxury', '1');\ngr_Inc.insert()\n```\n\nReturned value:\n\n```\n{\n  \"u_luxury\" : \"true\"\n}\n```\n\n## GlideElementDynamicAttributeStore - setDynamicAttributeDisplayValues\\(GlideDynamicAttributeStore values\\)\n\nSets the display values specified in the passed GlideDynamicAttributeStore 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.\n\n<table id=\"table_o32_b4d_bbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nvalues\n\n</td><td>\n\n[GlideDynamicAttributeStore](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttStoreAPI.md)\n\n</td><td>\n\nObject 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:\n\n```\n{\n  \"color\":\"Blue\",\n  \"make\":\"Ford\",\n  \"model\":\"Mustang\"\n}\n```\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|GlideElementDynamicAttributeStore|Object that contains the updated glide element.|\n\nThe following code example shows how to call this method.\n\n```\nvar daStore = new GlideDynamicAttributeStore();\ndaStore.setDynamicAttributeValue('make', 'Ford');\ndaStore.setDynamicAttributeValue('model', 'Mustang');\ndaStore.setDynamicAttributeValue('color', 'Blue');\ngs.info(\"daStore: \" + daStore);\n\nvar gr_Car = new GlideRecord('u_car_fleet');\ngr_Car.query();\nwhile(gr_Car.next()) {\n  var glideElement = gr_Car.getElement('u_dyn_attr_store');\n  glideElement.setDynamicAttributeValues(daStore);\n  gr_Car.update();\n}\n```\n\nOutput:\n\n```\ndaStore: {\"color\":\"Blue\",\"model\":\"Mustang\",\"make\":\"Ford\"}\n```\n\n"}}