Get undefined error when adding new object to msg.payload

I need a 2nd set of eyes because I'm at a loss to figure out this problem...

In a Function node, I am attempting to run this command:

msg.payload.lat = 30.05;

When I execute the flow, I get the error:
TypeError: Cannot set properties of undefined (setting 'lat')

Since both msg and payload are valid why am I not able to add a new object to msg.payload?

You are trying to set a lat property on "something" - this "something" has a prerequisite: it has to be an object before you can assign a property.

msg.payload = 'blabla' < not an object
msg.payload.lat = 30.50 = error.

msg.payload = {} < is an object
msg.payload.lat = 30.50 = ok

Forgot to include that this is the first line in my Function:

msg.payload = {};

Post your complete function as we can only guess what is happening.

Here is a copy of my code:

msg.payload = {};
msg.payload.name = "K5WH-117";
msg.paylaod.lat = 30.05;
msg.payload.lon = -95.53;
return msg;

Check typo.

1 Like

(wiping the egg from my face)... well SON OF A ... this is why I needed a 2nd set of eyes. Thank You!

3 Likes

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