# Please - Why won't this work

**URL:** <https://discourse.nodered.org/t/please-why-wont-this-work/37403>\
**Category:** General\
**Created:** [12 December 2020 15:33 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403 "2020-12-12T15:33:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FatPilot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fatpilot/32/38329_2.png) [@FatPilot](https://discourse.nodered.org/u/FatPilot)\
**Post date:** [12 December 2020 15:33 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/1 "2020-12-12T15:33:24Z")

</div>

I just can't get this to work.  
Thanks in advance  
Cheers

// All the vars below are of type string

var reg = msg.payload.registration;  
var actype = msg.payload.type;  
var alt = String(msg.payload.altitude);  
var squawk = msg.payload.squawk;  
var time = msg.payload.time;  
var hdg = String(msg.payload.hdg);  
var message="";

msg.topic = reg + " Overflew @ " + time;  
message = actype + " " + reg + " Overflew @ " + time +" Altitude " + alt +" HDG " + hdg + " Sqk " + squawk;

outputmsg = {  
payload: message  
};

return [outputmsg];

I get this output  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aaae0e604e0bca5ced74b7dad8924ef9b205e0d0.png)

---

<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:** [12 December 2020 15:54 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/2 "2020-12-12T15:54:08Z")

</div>

Show us what a debug node showing the input to the function contains. The output suggests that, for example, `msg.payload.type` does not exist.

For future reference, when pasting code, logs, flows etc please use the `</>` button at the top of the text entry window to format it correctly.

---

<div class="post-metadata">

**Author:** ![FatPilot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fatpilot/32/38329_2.png) [@FatPilot](https://discourse.nodered.org/u/FatPilot)\
**Post date:** [12 December 2020 16:25 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/3 "2020-12-12T16:25:08Z")

</div>

Hi Colin,  
this is what is going in

Cheers.  
Paul.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/0/a03118d2cef7ace22c4951b488935c6ca8722949.png)

---

<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:** [12 December 2020 16:30 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/4 "2020-12-12T16:30:02Z")

</div>

If you look carefully you will see there is no `msg.payload.type`, there is a `msg.payload.Type` though. Does that help?

---

<div class="post-metadata">

**Author:** ![FatPilot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fatpilot/32/38329_2.png) [@FatPilot](https://discourse.nodered.org/u/FatPilot)\
**Post date:** [12 December 2020 16:47 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/5 "2020-12-12T16:47:32Z")

</div>

Hi Colin,  
Thank you for your attention to detail.  
Solved the problem by changing them all!

Cheers.  
Paul.

---

<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:** [12 December 2020 17:11 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/6 "2020-12-12T17:11:01Z")

</div>

In case you are interested it is considered good practice to re-use the input message rather than creating a new message. That allows users to add data properties (eg `msg.mydata`)to a message and pass it through nodes without losing the extra information. Also it usually saves a bit of code. So in your case you could replace the end section with

```auto
msg.payload = actype + " " + reg + " Overflew @ " + time +" Altitude " + alt +" HDG " + hdg + " Sqk " + squawk;
return msg

```

You don't need to provide an array to the return statement unless you are sending to multiple outputs.

---

<div class="post-metadata">

**Author:** ![FatPilot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fatpilot/32/38329_2.png) [@FatPilot](https://discourse.nodered.org/u/FatPilot)\
**Post date:** [13 December 2020 01:30 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/7 "2020-12-13T01:30:50Z")

</div>

Colin, thank you.

---

<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:** [27 December 2020 01:31 UTC](https://discourse.nodered.org/t/please-why-wont-this-work/37403/8 "2020-12-27T01:31:02Z")

</div>

Closed on 27 December 2020 01:31 UTC

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