# Payload\[variable\]

**URL:** https://discourse.nodered.org/t/payload-variable/48650
**Category:** General
**Created:** [20 July 2021 12:08 UTC](https://discourse.nodered.org/t/payload-variable/48650 "2021-07-20T12:08:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![PiMo131](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pimo131/32/34978_2.png) [@PiMo131](https://discourse.nodered.org/u/PiMo131)
#### Post date: [20 July 2021 12:08 UTC](https://discourse.nodered.org/t/payload-variable/48650/1 "2021-07-20T12:08:59Z")

</div>

Hello,

I am using below code to retrieve data from a payload.

```auto
var row = flow.get("row");

msg.payload = msg.payload[row].payload;

return msg;

```

This is not working. Is there a way to set make the number variabel?  
msg.payload[0].payload, msg.payload[1].payload, msg.payload[2].payload, etc.

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [20 July 2021 12:15 UTC](https://discourse.nodered.org/t/payload-variable/48650/2 "2021-07-20T12:15:59Z")

</div>

This works well if:  
f`low.get("row")` gives a number

and  
incoming `msg.payload` carry an array which has that amount of members so it does not look outside of array boundaries

and  
incoming `msg.payload[the number of the row]` has property called with name `payload`.

If you make sure those conditions are met, It should work flawlessly.  
Use debugging options to be sure.

Also such kind of functions should have some fallback for situations when conditions are not met.  
Depending on what the real case is but I'd start with easy things like:

```auto
var row = flow.get("row")

if(row == undefined){
   row = 0
}

```

---

<div class="post-metadata">

### Author: ![PiMo131](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pimo131/32/34978_2.png) [@PiMo131](https://discourse.nodered.org/u/PiMo131)
#### Post date: [20 July 2021 13:18 UTC](https://discourse.nodered.org/t/payload-variable/48650/3 "2021-07-20T13:18:17Z")

</div>

Thanks!  
the value had to changed to a number, that did the trick

---

<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: [3 August 2021 13:18 UTC](https://discourse.nodered.org/t/payload-variable/48650/4 "2021-08-03T13:18:41Z")

</div>

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