# Function tried to send a message of type string

**URL:** https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505
**Category:** General
**Created:** [23 August 2018 08:52 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505 "2018-08-23T08:52:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![podi62](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@podi62](https://discourse.nodered.org/u/podi62)
#### Post date: [23 August 2018 08:52 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505/1 "2018-08-23T08:52:56Z")

</div>

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];

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [23 August 2018 09:03 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505/2 "2018-08-23T09:03:32Z")

</div>

Change

> [@podi62](#):
>
> var msg1=msg.payload;  
> var msg2=msg.payload

to

```auto
var msg1={};
var msg2={};

```

---

<div class="post-metadata">

### Author: ![podi62](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@podi62](https://discourse.nodered.org/u/podi62)
#### Post date: [23 August 2018 09:06 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505/3 "2018-08-23T09:06:38Z")

</div>

> [@zenofmud](#):
>
> var msg1={}; var msg2={};

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

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [23 August 2018 09:08 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505/4 "2018-08-23T09:08:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![podi62](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@podi62](https://discourse.nodered.org/u/podi62)
#### Post date: [23 August 2018 09:18 UTC](https://discourse.nodered.org/t/function-tried-to-send-a-message-of-type-string/2505/5 "2018-08-23T09:18:17Z")

</div>

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