# How to access attribute tags in javascript node

**URL:** <https://forums.losant.com/t/how-to-access-attribute-tags-in-javascript-node/4344>\
**Category:** Help\
**Tags:** workflow\
**Created:** [February 3, 2022, 8:44pm UTC](https://forums.losant.com/t/how-to-access-attribute-tags-in-javascript-node/4344 "2022-02-03T20:44:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Cline](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@Edward\_Cline](https://forums.losant.com/u/Edward_Cline)\
**Post date:** [February 3, 2022, 8:44pm UTC](https://forums.losant.com/t/how-to-access-attribute-tags-in-javascript-node/4344/1 "2022-02-03T20:44:39Z")

</div>

I am trying to access the value of an attribute tag from a device in a workflow using the javascript node. The workflow gets the device, all attributes and attribute tags and saves them on the payload. From within the javascript node I try to access an att tag but get an error:

```auto
FunctionNodeTypeError
Cannot read properties of undefined (reading 'attributeTags')

```

The code that is attempting to access the tag is:

```auto
/* attribute calc-flow is for airflow, attribute tag ductAreaCuFt holds duct csa */
var ductCsa = Number(4);
ductCsa = Number(payload.working.deviceId.attributes.calc-flow.attributeTags.ductAreaCuFt);

```

The payload showing in the workflow debug pane is:  
 ![Capture1](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0c58f49e9e327db3e41e7cea8b1a3e73c5304c2a.png)

How can I acces the value ‘4’ stored in this attribute tag?

Also, what is a way a javascript node can test the payload to see if an element exists before accessing it so the entire workflow won’t error?

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [February 3, 2022, 9:31pm UTC](https://forums.losant.com/t/how-to-access-attribute-tags-in-javascript-node/4344/2 "2022-02-03T21:31:45Z")

</div>

First, your problem lies here (emphasis added) -

payload.working.deviceId.attributes. **calc-flow**.attributeTags.ductAreaCuFt

[Dot notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#dot_notation) does not support hyphens in property names (along with some other special characters). Instead, you’ll have to use [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#bracket_notation) for that portion of the path:

```auto
payload.working.deviceId.attributes['calc-flow'].attributeTags.ductAreaCuFt

```

> Also, what is a way a javascript node can test the payload to see if an element exists before accessing it so the entire workflow won’t error?

There is! The Function Node supports [optional chaining](https://javascript.info/optional-chaining) for safely accessing deep object properties that may not exist.

So using your example from above, a safe way to access the property would be …

```js
const myValue = payload.working?.deviceId?.attributes?.['calc-flow']?.attributeTags?.ductAreaCuFt;

```

Note you need that period before the bracket notation when doing optional chaining.

---

<div class="post-metadata">

**Author:** ![Edward\_Cline](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@Edward\_Cline](https://forums.losant.com/u/Edward_Cline)\
**Post date:** [February 4, 2022, 7:37pm UTC](https://forums.losant.com/t/how-to-access-attribute-tags-in-javascript-node/4344/3 "2022-02-04T19:37:18Z")

</div>

Thanks, that works well.
