Send an array value to url

When I get a value from a calculator node, I want to get the value thru a function node and supply the value to a url. If the value is negative, I want to insert the value zero.
I've tried using param but something is wrong. Maybe I need to change the array to a message first?

You haven’t provided enough information. What calculator node? What are you doing in the function node? What should the url look like?

Joining two values
Comparing them
Sending it through the funciton node

Adding the value in the url
Getting this in return after a while

Cany you create a small flow demovstrating the issue. Use an inject node to start off. Then export your low and attach it to a reply.

It would be useful to give the ful name of the calculation node -i.e. node-red-contrib-?????

I am nearly there now, but the calculator can't send out a negative value.
So I want to do math in a function node instead. But I dont know how to do this.
Here is a picture. Row 3 is just for demonstration.

He when posting code, it is far better to copy + paste the code into a code block (click the </> button in the reply toolbar)

that way, someone assisting you doesnt have to read & re-type out the code from your screenshot.

As for using a function to deduct a from b...

msg.payload = b - a;

if you want that to be a value inside an array then...

msg.payload = [b - a];


msg['param'] = 
parseInt(msg['payload']) <= 0 ? 0:
return msg;

When I get a negative value in the payload, I want the output to be zero.
What have I done wrong here

Did you realise the result will be in msg.param not msg.payload?

Also note that msg['param'] is the same as msg.param. You only need to use the square bracket notation if the property name includes special characters.

msg.param will be empty so should not be the 3rd part of parseInt(msg['payload']) <= 0 ? 0 : msg['param'];

This might be a bit better...

var pl = parseInt(msg.payload);
msg.origPayload = pl; //for checking in debug panel
msg.param = pl < 0 ? 0 : pl;
return msg;

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