# "Cannot read property 'sum:' of undefined"

**URL:** <https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565>\
**Category:** General\
**Created:** [5 November 2019 21:18 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565 "2019-11-05T21:18:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![genericfeature](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@genericfeature](https://discourse.nodered.org/u/genericfeature)\
**Post date:** [5 November 2019 21:18 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/1 "2019-11-05T21:18:15Z")

</div>

Hello there,

when using a Change/Set function on a certain message I get the error mentioned in the title.  
I am using Node Red in Siemens Mindsphere environment.  
The object is looking like this:

```auto
5.11.2019, 22:11:09.975node: 3ce216b3.c1054a
7c14dc0b6f2448caa676cd67a4626e47/Siwa_Fridge_Aspect/Coca_Cola_L: msg: Object
object
Coca_Cola_L_qc: object
_type: "number"
minvalue: 0
maxvalue: 0
count: 1
sum: 0
average: 0
Coca_Cola_L: object
_type: "number"
minvalue: 18
maxvalue: 18
count: 1
sum: 18
average: 18

```

The change function was taken from the palette. I used the debug "copy path" function to pick the values path and use it in the change function with the set operation -- sio, I followed pretty much the user guide.

Any idea what to do here?

Thank you in advance,  
Konstantin

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 November 2019 21:23 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/2 "2019-11-05T21:23:03Z")

</div>

the property name would just be `sum` not `sum:`  
: is used as the separator between the property name and its value `sum` : `0`

---

<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:** [5 November 2019 21:31 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/3 "2019-11-05T21:31:18Z")

</div>

If that doesn't fix it show us how you have configured the change node.

---

<div class="post-metadata">

**Author:** ![genericfeature](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@genericfeature](https://discourse.nodered.org/u/genericfeature)\
**Post date:** [6 November 2019 20:52 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/4 "2019-11-06T20:52:12Z")

</div>

Hi,  
Thanks for the feedback so far. Removing the ":" does not change the behaviour, the error message is:

> "Cannot read property 'sum' of undefined"

The change node is looking very basic:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/58a33c6952714f41196aa11655d7aaa84e2c639b.png)

As mentioned, I just took the Debug "copy path" function and put this into the change node.

Cheers  
Konstantin

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 November 2019 20:59 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/5 "2019-11-06T20:59:52Z")

</div>

Is it possible that a message with a different format is arriving at that Change node? Do you still have a Debug node alongside the Change node so you can verify exactly what is being passed into it when you see the error?

---

<div class="post-metadata">

**Author:** ![genericfeature](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@genericfeature](https://discourse.nodered.org/u/genericfeature)\
**Post date:** [7 November 2019 07:56 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/6 "2019-11-07T07:56:12Z")

</div>

The flow is looking like that:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/27ecd6749490f6be484d327090952572bd2eb4e2.png)

The debug node is directly connected to the "read aggregates" node. The payload at the debug node is what I posted in my initial post.  
The error is created from the change node.  
At the change node output the payload remains unchanged -- so it is exactly what the "read aggregates" node delivers.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [7 November 2019 08:20 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/7 "2019-11-07T08:20:10Z")

</div>

> [@genericfeature](#):
>
> ```auto
> 5.11 .2019, 22: 11: 09.975 node: 3 ce216b3.c1054a
> 7 c14dc0b6f2448caa676cd67a4626e47 / Siwa_Fridge_Aspect / Coca_Cola_L: msg: Object
> object
> Coca_Cola_L_qc: object
> _type: "number"
> minvalue: 0
> maxvalue: 0
> count: 1
> sum: 0
> average: 0
> Coca_Cola_L: object
> _type: "number"
> minvalue: 18
> maxvalue: 18
> count: 1
> sum: 18
> average: 18
> 
> ```

if this is your msg.payload than try this:

```auto
msg.payload.Coca_Cola_L.sum

```

---

<div class="post-metadata">

**Author:** ![genericfeature](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@genericfeature](https://discourse.nodered.org/u/genericfeature)\
**Post date:** [7 November 2019 08:24 UTC](https://discourse.nodered.org/t/cannot-read-property-sum-of-undefined/17565/8 "2019-11-07T08:24:34Z")

</div>

@cflurin -- that helped! Getting the right value now.  
Strange that the copy function is not picking the path properly

Thank you very much!
