Function tried to send a message of type string

#1

I.m sure this has been asked before but can't find a solution and tried searching for the relevant javascript solution but didn't help. I'm trying to get 2 values out of a function and get "Function tried to send a message of type string"
Function code below.

global.set("pushed", 1);
global.set("override", 0);
var p = global.get("pushed");
p=p.toString();
var o = global.get("override");
o=o.toString();
var msg1=msg.payload;
var msg2=msg.payload
msg1.payload=p;
msg2.payload=o;
return [ msg1 , msg2 ];

0 Likes

#2

Change

to

var msg1={};
var msg2={};
0 Likes

#3

That worked perfectly. Many thanks. Hope it helps other newbies to JS and Node-Red.

0 Likes

#4

I think you should also carefully read the manual https://nodered.org/docs/user-guide/messages and do some experiments to understand how to deal with msg Object and its properties.

0 Likes

#5

Thank you. I'll bookmarked that page and will give it a go.

0 Likes