"Function tried to send a message of type string" error

Please help me to resolve this issue, that would be a great support of yours to me !!!
var grad=msg.payload
if (grad>85)
{
msg.grade="S";
}
else if (grad<=85 && grad>80)
{
msg.grade="A";
}

else if (grad<=80 && grad>70)
{
msg.grade="B";

}

else if (grad<=70 && grad>60)
{
msg.grade="C"

}

else if (grad<=60 && grad>50)
{
msg.grade="D";

}

else if (grad<=50 && grad>40)
{
msg.grade="E";

}

else {
msg.grade="Fail";
}
return msg.grade;

As the error says, your function is returning a String object, rather than a message object.

If you look at the end of your function you have:

return msg.grade

Which means you are returning the value of msg.grade - a String, not a complete message object.

Change that to:

return msg;

I tried return msg; instead of ms.grade , getting value same value in msg.payload instead of string

You are putting the value in msg.grade not msg.payload. Add a debug node showing the output and set it to Show Complete Message and you will see what is there. Also I suggest watching the videos 'node red essentials' which will save you a lot of time. Also read the the docs Working With Messages and the one on Writing Functions.

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