# Send an array value to url

**URL:** <https://discourse.nodered.org/t/send-an-array-value-to-url/40421>\
**Category:** General\
**Created:** [5 February 2021 06:43 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421 "2021-02-05T06:43:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dowermyr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dowermyr/32/31547_2.png) [@dowermyr](https://discourse.nodered.org/u/dowermyr)\
**Post date:** [5 February 2021 06:43 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/1 "2021-02-05T06:43:32Z")

</div>

Hi!  
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?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 February 2021 09:54 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/2 "2021-02-05T09:54:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dowermyr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dowermyr/32/31547_2.png) [@dowermyr](https://discourse.nodered.org/u/dowermyr)\
**Post date:** [5 February 2021 10:19 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/3 "2021-02-05T10:19:20Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/204cf1907be6338a5493ea64e6ad0a521ad01325.png)  
Joining two values  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/500363460011f7fa75df7f0952b2a3264fc28fcd.png)  
Comparing them  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ea2ae9246ce179e1b3e809d9586d2d574e0b778.png)  
Sending it through the funciton node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8aa021fef7ba5e37477be841d8a0139c9fba8939.png)  
Adding the value in the url  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b502dd60e570a848cfb0041246d40d684ef639e.png)  
Getting this in return after a while

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 February 2021 12:33 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/4 "2021-02-05T12:33:38Z")

</div>

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-?????

---

<div class="post-metadata">

**Author:** ![dowermyr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dowermyr/32/31547_2.png) [@dowermyr](https://discourse.nodered.org/u/dowermyr)\
**Post date:** [5 February 2021 13:33 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/5 "2021-02-05T13:33:23Z")

</div>

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.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a714b641c6567268bea6e10d6a90be37d01ac709.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 February 2021 13:40 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/6 "2021-02-05T13:40:34Z")

</div>

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...

```auto
msg.payload = b - a;

```

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

```auto
msg.payload = [b - a];

```

---

<div class="post-metadata">

**Author:** ![dowermyr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dowermyr/32/31547_2.png) [@dowermyr](https://discourse.nodered.org/u/dowermyr)\
**Post date:** [5 February 2021 13:48 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/7 "2021-02-05T13:48:47Z")

</div>

Thanks!

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

```

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 February 2021 14:04 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/8 "2021-02-05T14:04:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 February 2021 14:06 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/9 "2021-02-05T14:06:52Z")

</div>

> [@dowermyr](#):
>
> When I get a negative value in the payload, I want the output to be zero.  
> What have I done wrong here

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...

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 February 2021 14:07 UTC](https://discourse.nodered.org/t/send-an-array-value-to-url/40421/10 "2021-02-19T14:07:33Z")

</div>

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