Having problems getting data out from mysql

I may trying to convert the array that I get from mysql to variable. Then array passes though my function node, the payload is unchanged ans still has the array as the payload.

Here is my function node

msg.FullName = msg.payload[0]['FullName'].toString();
return msg;

I have also tried this and no luck

msg.name = msg.payload[0].FullName.toString();

Here is the output from mysql with single match to mysql request. I would like it so that msg.FullName would be testfullname in this case.
image

I am also getting no errors.

You are assigning the converted value directly to the message object as msg.FullName or msg.name.
If you want to see it in the payload, you have to assign it there. :slightly_smiling_face:

So try something like

msg.payload = msg.payload[0]['FullName'].toString();

Also, I would add some plausibility checks for the input data. E.g. the array can be empty if there are no results, the string could be null, ...

Another suggestion: To improve readability in the debug bar remove the query from the message after you used it with delete msg.topic;

Thanks for the tip about delete msg.topic;

msg.payload = msg.payload[0]['FullName'].toString();

This did work but how do I get more than more var out?
I have updated mysql request to pull all of the data that I want
image

Normally you could just assign the result set to msg.payload, like

msg.payload = msg.payload[0] to get an object like {FullName: 'testfullname', TalkTitle: '...'}...

Those strings shouldn't be buffers in the first place, which data types are you using for these fields? That shouldn't happen with varchar or char, they should be normal strings.

If you want to keep it that way, you need to convert each one and assign them manually.

msg.payload = {
    FullName: msg.payload[0]['FullName'].toString(),
    TalkTitle: msg.payload[0]['TalkTitle'].toString()

}

...and so on.

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