# Error in getting part of an object

**URL:** <https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017>\
**Category:** General\
**Created:** [14 October 2022 08:13 UTC](https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017 "2022-10-14T08:13:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [14 October 2022 08:13 UTC](https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017/1 "2022-10-14T08:13:59Z")

</div>

I have this simple function to read the specific lines of my interest in a message and assign the topic.

```auto
msg.payload = msg.payload.commonAnnotations.description;
msg.topic = msg.payload.commonAnnotations.summary;
return msg

```

I have copied both paths from the debug window.

 ![Screenshot 2022-10-14 at 10.05.14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66a9a4ec5db13abc50ffad7fdba5edb4565181c8.jpeg)

The msg.topic is giving error

> "TypeError: Cannot read properties of undefined (reading 'summary')"

I don't understand why and how to resolve this.  
The msg.payload it is fine. I can get it without errors.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 October 2022 08:20 UTC](https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017/2 "2022-10-14T08:20:29Z")

</div>

> [@FeliceM](#):
>
> I have this simple function to read the specific lines of my interest in a message and assign the topic.
> 
> ```auto
> msg.payload = msg.payload.commonAnnotations.description;
> msg.topic = msg.payload.commonAnnotations.summary;
> return msg
> 
> ```

Your first line replaces msg.payload.  
Therefore msg.payload.commonAnnotations.summary no longer exists.

Set msg.topic first.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 October 2022 08:47 UTC](https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017/3 "2022-10-14T08:47:16Z")

</div>

You can avoid that by using something like

```auto
let annotations = msg.payload.commonAnnotations
msg.payload = annotations.description;
msg.topic = annotations.summary;
return msg

```

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [14 October 2022 14:26 UTC](https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017/4 "2022-10-14T14:26:04Z")

</div>

Thank you. I was blind!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 October 2022 14:26 UTC](https://discourse.nodered.org/t/error-in-getting-part-of-an-object/69017/5 "2022-10-28T14:26:05Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
