# Variable inside payload

**URL:** https://discourse.nodered.org/t/variable-inside-payload/57590
**Category:** General
**Created:** [1 February 2022 11:58 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590 "2022-02-01T11:58:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![toppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toppe/32/55440_2.png) [@toppe](https://discourse.nodered.org/u/toppe)
#### Post date: [1 February 2022 11:58 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/1 "2022-02-01T11:58:34Z")

</div>

Hi,

I'm having the following function:

```auto
        data :{ 
        title : msg.title,
        message : msg.message,
        data: {
            push: {
                sound: {
                    name: 'default',
                    critical: msg.setCritical,
                    volume: 1
                }
            },
            actions: [msg.action],
        }
    },
        service : msg.receiver
    }

```

I'm also having this:

```auto
if(msg.imageurl){ msg.setImage = "image: https://github.com/home-assistant/assets/blob/master/logo/logo.png?raw=true"; }

```

But how can I pas the `msg.setImage` after `actions: [msg.action],`?

It's not possible to already put `image: msg.setImage` to it and send a empty image because it's shows a 404 error image.

---

<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: [1 February 2022 15:08 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/2 "2022-02-01T15:08:14Z")

</div>

I don't understand what you have showed us.

> [@toppe](#):
>
> I'm having the following function:

That appears to be part of an object, not a function.

> [@toppe](#):
>
> how can I pas the `msg.setImage` after `actions: [msg.action],`

Again I don't understand. If you want to include the contents of msg.setImage into the structure then using `image: msg.setImage` is the correct way to do it. If you do that and look at the result in a debug node (before you do anything else with it) what do you see?

---

<div class="post-metadata">

### Author: ![toppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toppe/32/55440_2.png) [@toppe](https://discourse.nodered.org/u/toppe)
#### Post date: [1 February 2022 15:39 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/3 "2022-02-01T15:39:03Z")

</div>

I've created a sub-flow with soms variables on the input side. This is in my function.

```auto

```

I would like to check if `msg.imageurl` got a value and if so, put is **after** `actions: [msg.action],`.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 February 2022 15:45 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/4 "2022-02-01T15:45:10Z")

</div>

```auto
if(msg.imageurl) {
   msg.payload.data.data.image = msg.imageurl;
}

```

Add something like this after you set the payload. this will check if msg.imageurl exist and add it to your payload.

---

<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: [1 February 2022 15:45 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/5 "2022-02-01T15:45:53Z")

</div>

Something like this after the `msg.payload = ...` statement

```auto
if (msg.imageurl) {
  msg.payload.data.data.image = msg.imageurl
}

```

---

<div class="post-metadata">

### Author: ![toppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toppe/32/55440_2.png) [@toppe](https://discourse.nodered.org/u/toppe)
#### Post date: [1 February 2022 15:50 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/6 "2022-02-01T15:50:03Z")

</div>

Thanks, did the trick!

---

<div class="post-metadata">

### Author: ![toppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toppe/32/55440_2.png) [@toppe](https://discourse.nodered.org/u/toppe)
#### Post date: [1 February 2022 15:50 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/7 "2022-02-01T15:50:17Z")

</div>

Thanks, 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: [2 April 2022 15:50 UTC](https://discourse.nodered.org/t/variable-inside-payload/57590/8 "2022-04-02T15:50:24Z")

</div>

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