# Nested subflows with permanent "localfilesystem" context storage

**URL:** <https://discourse.nodered.org/t/nested-subflows-with-permanent-localfilesystem-context-storage/52628>\
**Category:** General\
**Created:** [23 October 2021 20:42 UTC](https://discourse.nodered.org/t/nested-subflows-with-permanent-localfilesystem-context-storage/52628 "2021-10-23T20:42:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TobyK](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TobyK](https://discourse.nodered.org/u/TobyK)\
**Post date:** [23 October 2021 20:42 UTC](https://discourse.nodered.org/t/nested-subflows-with-permanent-localfilesystem-context-storage/52628/1 "2021-10-23T20:42:50Z")

</div>

Hi,

i run into some trouble with permanent value storage in nested subflows. I don’t know if this is generally possible, so I want to ask before open an issue.  
I want to save some state variables in flow or node context level for different nested subflow levels. The subflows are not the same. What I observe is that only the first level is saved to “localfilesystem”. The other levels are undefined after a restart. I checked the same for function nodes ans context storage.  
I created a simple testbench:

A flow with two nested subflows (level1 and level2). The testdata is written into is subflow flow context from the top-flow. The data is printed to debug window a short time after restart of the flow.

The debug window below shows:

- Line 1-2: uninizialized two subflow context storages
- Line 3: send data to storage
- Line 4-5: read context storage after restart flow

Is this behavior normal? I didn’t found any info in relation to this specific topic.

A big thank for your help.  
Greetings  
TobyK

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f39bdbaf2f820843290573430f9fdcca9f289b38.png)

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20038d1092f46ce0ac4c9fa3ee81c31af621c531.png)

---

<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:** [23 October 2021 20:46 UTC](https://discourse.nodered.org/t/nested-subflows-with-permanent-localfilesystem-context-storage/52628/2 "2021-10-23T20:46:32Z")

</div>

I would expect it to work... but I can't say it's a specific combination I've ever tested.

Could you share your example flow? I'll investigate next week.

---

<div class="post-metadata">

**Author:** ![TobyK](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TobyK](https://discourse.nodered.org/u/TobyK)\
**Post date:** [23 October 2021 20:53 UTC](https://discourse.nodered.org/t/nested-subflows-with-permanent-localfilesystem-context-storage/52628/3 "2021-10-23T20:53:06Z")

</div>

Thanks for the response.

```auto
[
    {
        "id": "7e0db130af3023fb",
        "type": "subflow",
        "name": "level2",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 140,
                "y": 160,
                "wires": [
                    {
                        "id": "5205d3ce0a7b11d2"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "cb683474f694958c",
        "type": "change",
        "z": "7e0db130af3023fb",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "#:(tofile)::level2",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 570,
        "y": 80,
        "wires": [
            [
                "0dfd1ab5128ccf38"
            ]
        ]
    },
    {
        "id": "0dfd1ab5128ccf38",
        "type": "debug",
        "z": "7e0db130af3023fb",
        "name": "level2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 80,
        "wires": []
    },
    {
        "id": "5205d3ce0a7b11d2",
        "type": "change",
        "z": "7e0db130af3023fb",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "#:(tofile)::level2",
                "pt": "flow",
                "to": "level2",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "ec161b52fcccc16c",
        "type": "inject",
        "z": "7e0db130af3023fb",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 210,
        "y": 80,
        "wires": [
            [
                "cb683474f694958c"
            ]
        ]
    },
    {
        "id": "b98a91283534ce8f",
        "type": "subflow",
        "name": "level1",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 60,
                "y": 160,
                "wires": [
                    {
                        "id": "8599f276d85be9a9"
                    },
                    {
                        "id": "d116b8a8ed7b3499"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "d116b8a8ed7b3499",
        "type": "subflow:7e0db130af3023fb",
        "z": "b98a91283534ce8f",
        "name": "",
        "env": [],
        "x": 520,
        "y": 240,
        "wires": []
    },
    {
        "id": "9f077f1f577ad0ba",
        "type": "change",
        "z": "b98a91283534ce8f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "#:(tofile)::level1",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 560,
        "y": 80,
        "wires": [
            [
                "2ffa5379e2e92a3a"
            ]
        ]
    },
    {
        "id": "2ffa5379e2e92a3a",
        "type": "debug",
        "z": "b98a91283534ce8f",
        "name": "level1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 80,
        "wires": []
    },
    {
        "id": "8599f276d85be9a9",
        "type": "change",
        "z": "b98a91283534ce8f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "#:(tofile)::level1",
                "pt": "flow",
                "to": "level1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 370,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "cccd01e20f14d038",
        "type": "inject",
        "z": "b98a91283534ce8f",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 200,
        "y": 80,
        "wires": [
            [
                "9f077f1f577ad0ba"
            ]
        ]
    },
    {
        "id": "67e8422ee554afd3",
        "type": "comment",
        "z": "b98a91283534ce8f",
        "name": "flow to msg payload",
        "info": "",
        "x": 550,
        "y": 20,
        "wires": []
    },
    {
        "id": "3cbe543c3d6d04d4",
        "type": "subflow:b98a91283534ce8f",
        "z": "f26c3086d2e77026",
        "name": "",
        "env": [],
        "x": 530,
        "y": 200,
        "wires": []
    },
    {
        "id": "6ad93daec4b7eeed",
        "type": "inject",
        "z": "f26c3086d2e77026",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Write Data to File",
        "payloadType": "str",
        "x": 330,
        "y": 200,
        "wires": [
            [
                "3cbe543c3d6d04d4",
                "ecd555748fa21395"
            ]
        ]
    },
    {
        "id": "ecd555748fa21395",
        "type": "debug",
        "z": "f26c3086d2e77026",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 560,
        "y": 160,
        "wires": []
    }
]

```

and in the settings:

```auto
    contextStorage: {
		tofile: { module: "localfilesystem"},
    	default: { module: "memory" }
    },

```

---

<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:** [22 December 2021 20:53 UTC](https://discourse.nodered.org/t/nested-subflows-with-permanent-localfilesystem-context-storage/52628/4 "2021-12-22T20:53:15Z")

</div>

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