undefined tag in node-red

We are getting the value in the SQL but one tag shows undefine.

d = new Date,
dformat = [d.getMonth()+1,
d.getDate(),
d.getFullYear()].join(’/’)+’ ‘+
[d.getHours(),
d.getMinutes(),
d.getSeconds()].join(’:’);

dtstmp = new Date().toString();

pld = “INSERT INTO [2WE TVS_NFFPP].[dbo].[MQTTData] "
pld = pld + “(DateTime, POD, Pos1_op, Pos1_ETA, Pos1_Weight, Pos1_rdy,Pos1_Length,Pos1_1_2_cut,Pos1_All_cut,Pos1_DD,Detex,Number_Ply) "
pld = pld + “VALUES (’”+ dformat+”’,’” + msg.payload.POD[0] + “’, '” + msg.payload.Pos1_op + “’,’” + msg.payload.Pos1_ETA + “’,’” + msg.payload.Pos1_Weight + “’,’” + msg.payload.Pos1_rdy + “’,’” + msg.payload.Pos1_Length + “’,’” + msg.payload.Pos1_1_2_cut + “’,’” + msg.payload.Pos1_All_cut + “’,’” + msg.payload.Pos1_DD + “’,’” + msg.payload.Detex + “’,’” + msg.payload.Number_Ply + “’)”

msg.topic = ‘’
msg.payload = pld
return msg;

this is the tags

In the CSV file, it shows POD-0 but we try with POD-0 also it shows 0 is not defined.

What I suggest you do is put a debug node in your flow.
Make sure you set the debug node to complete msg object… Like this;

image

Run the flow, then in your debug tab you will be able to see exactly which one of your tags is undefined and then you can go back in your flow and fix it.

Also, in this post, you forgot to include the image from your other post;

Posting to the forums (rather than emailing me) works better to get support as more people can see and help…

@a.khan replies…

The Tag1:EXT037867

But after json is shown POD:undefined.

Reading from MQTT:

Debug after MQTT reading

9/25/2020, 11:44:35 PMnode: 487c9584.6a76dc

readings/ : msg : Object

object

topic: “readings/”

payload: “{“connected”:1,“Detex”:2200,“Number_Ply”:3,“Pos1_1_2_cut”:“OFF”,“Pos1_All_cut”:“OFF”,“Pos1_DD”:“OFF”,“Pos1_ETA”:18,“Pos1_Length”:11.306,“Pos1_op”:84.549,“Pos1_rdy”:“OFF”,“Pos1_Weight”:12.26186,“Tag1”:“EXT037867”,“timestamp”:1601063074}”

qos: 0

retain: false

_msgid: “1084c79f.a6d698”

Debug after json format convert going to SQL node:

9/25/2020, 11:44:35 PMnode: 3cdb5ae5.2dec26

msg : Object

object

topic: “”

payload: “INSERT INTO [2WE TVS_NFFPP].[dbo].[MQTTData] (DateTime, POD, Pos1_op, Pos1_ETA, Pos1_Weight, Pos1_rdy,Pos1_Length,Pos1_1_2_cut,Pos1_All_cut,Pos1_DD,Detex,Number_Ply) VALUES (‘9/25/2020 23:44:35’,‘undefined’, ‘84.549’,‘18’,‘12.26186’,‘OFF’,‘11.306’,‘OFF’,‘OFF’,‘OFF’,‘2200’,‘3’)”

qos: 0

retain: false

_msgid: “1084c79f.a6d698”

Its hard to see from the wall of un-formatted text, perhaps screenshots would be better…

But, at a guess you are bringing in your data Tag1, but then you are sending it to SQL as POD.
I do not see your code in the debug, so I have to ask, are you extracting Tag1 from the original payload and moving it into a variable called POD?

Please show the code that does this function.

POD is undefined - it isn’t in your payload, msg.payload.POD doesn’t exist. You need to fix that. What do you expect to be in there, and where is it coming from?

1 Like

thanks, it is working, the POD tag was array and node-red doesn’t support array, so I convert into string.

Thanks for letting us know.

Also Node-RED DOES support arrays (I use them in a personal project a LOT).
For more information on using arrays in Node-RED check out these links.

https://cookbook.nodered.org/basic/operate-on-array

https://flows.nodered.org/flow/139d4107a2483732904f