# Setting flow context not working?

**URL:** https://discourse.nodered.org/t/setting-flow-context-not-working/6245
**Category:** General
**Created:** [31 December 2018 02:02 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245 "2018-12-31T02:02:14Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ScottChapman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scottchapman/32/4838_2.png) [@ScottChapman](https://discourse.nodered.org/u/ScottChapman)
#### Post date: [31 December 2018 02:02 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/1 "2018-12-31T02:02:14Z")

</div>

First of all I am running 0.16.2 (running on Jessie raspberry pi)

I have a flow that has a change node where I set a property on the flow context.

This doesn't appear to be getting set (as far as I can tell). To test it I have a function right after the change node that sets msg.flow to the flow object, then a debug node which dumps the entire msg. Basically like this:

```auto
[
    {
        "id": "4a64d7ea.ffaa88",
        "type": "inject",
        "z": "2de8ef9b.ec8fe",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 136.5,
        "y": 129.5,
        "wires": [
            [
                "72e38345.25e72c"
            ]
        ]
    },
    {
        "id": "72e38345.25e72c",
        "type": "change",
        "z": "2de8ef9b.ec8fe",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "flow",
                "to": "whatever",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 317.5,
        "y": 134.5,
        "wires": [
            [
                "ae3819fa.1cb0a8"
            ]
        ]
    },
    {
        "id": "ae3819fa.1cb0a8",
        "type": "function",
        "z": "2de8ef9b.ec8fe",
        "name": "get flow",
        "func": "msg.payload = flow.payload\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 556.5,
        "y": 161.5,
        "wires": [
            [
                "c5119dd5.5fe09"
            ]
        ]
    },
    {
        "id": "c5119dd5.5fe09",
        "type": "debug",
        "z": "2de8ef9b.ec8fe",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 645.5,
        "y": 238,
        "wires": []
    }
]

```

Any ideas?

---

<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: [31 December 2018 06:14 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/2 "2018-12-31T06:14:25Z")

</div>

Upgrade...current version of NR is 0.19.5

---

<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: [31 December 2018 09:26 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/3 "2018-12-31T09:26:59Z")

</div>

Since you have that version you presumably did not use the recommended method for installing node-red. See here for how to upgrade it:  
[https://nodered.org/docs/hardware/raspberrypi](https://nodered.org/docs/hardware/raspberrypi)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [31 December 2018 09:33 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/4 "2018-12-31T09:33:19Z")

</div>

Hi @ScottChapman

Whilst everyone has been quick to recommend you upgrade (which is certainly worthwhile), here what's going in with your flow...

To access a flow context property from a Function node, you need to use:

```auto
msg.payload = flow.get('payload');

```

See [this page](https://nodered.org/docs/writing-functions#storing-data) for details - although those docs do also cover things only available on the latest version.

---

<div class="post-metadata">

### Author: ![ScottChapman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scottchapman/32/4838_2.png) [@ScottChapman](https://discourse.nodered.org/u/ScottChapman)
#### Post date: [31 December 2018 13:58 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/5 "2018-12-31T13:58:12Z")

</div>

Thanks, that was it!

my node-red was basically what was included in the distro, so I'll go ahead and upgrade.

thanks!

---

<div class="post-metadata">

### Author: ![ScottChapman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scottchapman/32/4838_2.png) [@ScottChapman](https://discourse.nodered.org/u/ScottChapman)
#### Post date: [31 December 2018 14:37 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/6 "2018-12-31T14:37:05Z")

</div>

related question...

Do I need to use a `change` node in my flow to actually change those values? Or is there some other way I can easily establish these flow properties (which I am basically using as configuration for the flow)?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [31 December 2018 14:57 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/7 "2018-12-31T14:57:23Z")

</div>

you can do it with a function node as per the link in Nicks post or with a change node

---

<div class="post-metadata">

### Author: ![ScottChapman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scottchapman/32/4838_2.png) [@ScottChapman](https://discourse.nodered.org/u/ScottChapman)
#### Post date: [31 December 2018 15:02 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/8 "2018-12-31T15:02:05Z")

</div>

Right, I assume that node needs to be linked to my other nodes in the flow.

I was just wondering if I can have a "configuration" node, that is just not linked to any other nodes, that essentially fires at startup to set up the configuration that is used by the flow.

Does that make sense? I realize I can just do what I was doing, but wanting to understand alternatives.

Thanks!

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [31 December 2018 15:14 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/9 "2018-12-31T15:14:01Z")

</div>

> [@ScottChapman](#):
>
> I was just wondering if I can have a "configuration" node, that is just not linked to any other nodes, that essentially fires at startup to set up the configuration that is used by the flow.

There is a contrib-node for this purpose but as you can do it with two core-nodes I wouldn't install a separate contrib-node (less maintenance efforts).

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [31 December 2018 15:23 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/10 "2018-12-31T15:23:27Z")

</div>

Take a look at [https://nodered.org/docs/writing-functions#global-context](https://nodered.org/docs/writing-functions#global-context)

You can store global context which is available over all flows.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [31 December 2018 15:45 UTC](https://discourse.nodered.org/t/setting-flow-context-not-working/6245/11 "2018-12-31T15:45:26Z")

</div>

or you can set an inject node to fire at start - to trigger a change node to set them all as you wish.
