node-red-contrib-image-tools icon indicating copy to clipboard operation
node-red-contrib-image-tools copied to clipboard

Unable to get "text" to accept a property as input.

Open JanJoh opened this issue 2 years ago • 5 comments

I _think i am trying to do something simple.

I have a mysql-node that returns the following msg.payload

image

To me, that would mean that I could use the following to access the data

image

But that just results in"TypeError: text.replace is not a function"

I've tried pretty much any string conversion trick I can think of, and I still cannot get "print" to accept dynamic input data.

What the heck am I missing?

JanJoh avatar Aug 21 '22 20:08 JanJoh

Try changing the type of the text field to jsonata & putting payload[0].day & '' as the expression.

Alternatively, add a function node before the image node& enter..

msg.payload[0].day = String (msg.payload[0].day)
return msg

Steve-Mcl avatar Aug 22 '22 05:08 Steve-Mcl

Try changing the type of the text field to jsonata & putting payload[0].day & '' as the expression.

Alternatively, add a function node before the image node& enter..

msg.payload[0].day = String (msg.payload[0].day)
return msg

Thank you for responding.

Now, J is not available in the image-node. Just "msg" "flow" or "global". It would be nice to have that as an input type. :) image

However, using a function node in front to process the data worked. But I really fail to see what makes that different from the methods i tried. But, this at least works as a workaround. Thank you.

JanJoh avatar Aug 22 '22 06:08 JanJoh

The issue is 7 is a number in JS, number.replace is not a function but string.replace is! (under the hood, your value is sanitised to prevent crashing & remove/convert non ASCII characters using the string.replace function)

image

In other words, you need to pass a value of string type (e.g. "7" not 7) to the text item

NOTE FOR SELF...

  • consider adding a .toString or raise an error stating "Value is not a string" to better aid users.

Steve-Mcl avatar Aug 23 '22 07:08 Steve-Mcl

The issue is 7 is a number in JS, number.replace is not a function but string.replace is!

Groaaan... I know better. I work with this stuff. I'm an engineer dammit.. But, staring at something for too long aparently makes you blind. Yeah, "Value is not a string" probably should snap me out of it sooner . ;)

JanJoh avatar Aug 23 '22 07:08 JanJoh

Hi I am a newbie to Node red and am having problems trying to use a variable in the text field as described here. I want to add such variables as temperature, humidity etc to my saved image. I understand from the above that I need to convert my variable to a string in a function node before the edit image node. I am not clear on the statement to add into the text box. As noted above the options are msg, flow, global. Help please on the way to reference the string created in the function node. Thanks Since writing I think I have worked out the solution. I used flow.set to take my string value and then choose the flow option in the text box.

pthelm avatar Mar 17 '23 01:03 pthelm