# Msg.reset inside subflow not working on delay

**URL:** https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238
**Category:** Dashboard
**Created:** [5 January 2023 16:56 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238 "2023-01-05T16:56:29Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 16:56 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/1 "2023-01-05T16:56:29Z")

</div>

I'm building an AV control system using node-red. One of my actions is for listening to music at night. In that action it sets a delay for 90 minutes to turn everything off. That works 100% correctly. In the other actions I send a msg to the night music subflow with msg.reset=true to cancel the delay. This is in case the night music was accidentally hit so you can hit the other action and have it cancel the delay so it doesn't shut everything off in 90 minutes. This msg.reset=true fails to cancel the delay 100% of the time.

To test it I created a subflow that prints the entire msg then has a delay for 2 minutes then displays the entire msg via the debug node. I have two injects in a flow to test it, one sends a msg to the subflow, the other sends a msg with msg.reset=true set. These work 100% of the time, hit the first one and you see the msg displayed and the delay is activated. 2 minutes later you see the entire msg displayed again. If you press the first inject then after that press the second inject you see the debug msg displayed from the first inject then the msg displayed with reset=true from the second inject but you don't see the msg displayed again from the debug node after the delay node. This works 100% of the time.

However, if I move the setting of the msg.reset into a subflow that will call the original test subflow that will fail 100% of the time even though the debug message shows msg.reset is set to true. It will always execute the debug node after the delay node. In other words, the start delay inject calls subflow A which is the one that has the delay. The cancel inject calls subflow B which uses a change node to set msg.reset=true then pass the msg to subflow A. You see the msg.reset=true in the debug log but the debug node after the delay is always executed thus it didn't cancel the delay.

Any ideas why the reset does not work correctly when initiated from within a subflow but does work correctly when initiated from within a flow?

---

<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 January 2023 17:14 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/2 "2023-01-05T17:14:00Z")

</div>

Hi. Can you provide a minimal sample flow that demonstrates this?

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 17:42 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/3 "2023-01-05T17:42:33Z")

</div>

As a new user it will not let me upload the exported flows.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 January 2023 18:08 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/4 "2023-01-05T18:08:56Z")

</div>

Hi @rpoole

You shouldn't need to attach the flow as a file - just include the JSON contents between 2 rows of 3 backticks

````auto
```
JSON / File contents 
```

````

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:11 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/5 "2023-01-05T18:11:17Z")

</div>

Cancel Delay Test flow  
...  
[  
{  
"id": "5000652e2e0639f2",  
"type": "subflow",  
"name": "Cancel Delay Failure",  
"info": "",  
"category": "",  
"in": [  
{  
"x": 180,  
"y": 140,  
"wires": [  
{  
"id": "93e904b826c5b927"  
}  
]  
}  
],  
"out": ,  
"env": ,  
"meta": {},  
"color": "#DDAA99"  
},  
{  
"id": "ca1fc825888ca8ad",  
"type": "subflow:93d1b74d61d4f90f",  
"z": "5000652e2e0639f2",  
"name": "",  
"x": 520,  
"y": 140,  
"wires":   
},  
{  
"id": "93e904b826c5b927",  
"type": "change",  
"z": "5000652e2e0639f2",  
"name": "",  
"rules": [  
{  
"t": "set",  
"p": "reset",  
"pt": "msg",  
"to": "true",  
"tot": "bool"  
}  
],  
"action": "",  
"property": "",  
"from": "",  
"to": "",  
"reg": false,  
"x": 320,  
"y": 140,  
"wires": [  
[  
"ca1fc825888ca8ad"  
]  
]  
},  
{  
"id": "93d1b74d61d4f90f",  
"type": "subflow",  
"name": "TestMsgCancel",  
"info": "",  
"category": "",  
"in": [  
{  
"x": 80,  
"y": 100,  
"wires": [  
{  
"id": "8e95cef841af3afe"  
},  
{  
"id": "1b3f56701316f785"  
}  
]  
}  
],  
"out": ,  
"env": ,  
"meta": {},  
"color": "#DDAA99"  
},  
{  
"id": "8e95cef841af3afe",  
"type": "delay",  
"z": "93d1b74d61d4f90f",  
"name": "",  
"pauseType": "delay",  
"timeout": "5",  
"timeoutUnits": "seconds",  
"rate": "1",  
"nbRateUnits": "1",  
"rateUnits": "second",  
"randomFirst": "1",  
"randomLast": "5",  
"randomUnits": "seconds",  
"drop": false,  
"allowrate": false,  
"outputs": 1,  
"x": 280,  
"y": 100,  
"wires": [  
[  
"f8bc75fb8ecb0338"  
]  
]  
},  
{  
"id": "f8bc75fb8ecb0338",  
"type": "debug",  
"z": "93d1b74d61d4f90f",  
"name": "",  
"active": true,  
"tosidebar": true,  
"console": false,  
"tostatus": false,  
"complete": ""delay finished"",  
"targetType": "jsonata",  
"statusVal": "",  
"statusType": "auto",  
"x": 480,  
"y": 100,  
"wires":   
},  
{  
"id": "1b3f56701316f785",  
"type": "debug",  
"z": "93d1b74d61d4f90f",  
"name": "",  
"active": true,  
"tosidebar": true,  
"console": false,  
"tostatus": false,  
"complete": "true",  
"targetType": "full",  
"statusVal": "",  
"statusType": "auto",  
"x": 270,  
"y": 40,  
"wires":   
},  
{  
"id": "aa2a0675de682cbc",  
"type": "tab",  
"label": "Cancel Delay Test",  
"disabled": false,  
"info": "",  
"env":   
},  
{  
"id": "e8c53ad359599fe8",  
"type": "inject",  
"z": "aa2a0675de682cbc",  
"name": "Set Delay",  
"props": [  
{  
"p": "payload"  
},  
{  
"p": "topic",  
"vt": "str"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": false,  
"onceDelay": 0.1,  
"topic": "",  
"payload": "",  
"payloadType": "date",  
"x": 120,  
"y": 140,  
"wires": [  
[  
"d04e986cf42f4425"  
]  
]  
},  
{  
"id": "77bd611303adafee",  
"type": "inject",  
"z": "aa2a0675de682cbc",  
"name": "Cancel Delay",  
"props": [  
{  
"p": "reset",  
"v": "true",  
"vt": "bool"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": false,  
"onceDelay": 0.1,  
"topic": "",  
"x": 130,  
"y": 180,  
"wires": [  
[  
"d04e986cf42f4425"  
]  
]  
},  
{  
"id": "d04e986cf42f4425",  
"type": "subflow:93d1b74d61d4f90f",  
"z": "aa2a0675de682cbc",  
"name": "",  
"x": 340,  
"y": 140,  
"wires":   
},  
{  
"id": "3433a4566b875615",  
"type": "comment",  
"z": "aa2a0675de682cbc",  
"name": "This works",  
"info": "This works setting msg.reset=true from within a flow",  
"x": 80,  
"y": 80,  
"wires":   
},  
{  
"id": "1c1812546a3e8f75",  
"type": "inject",  
"z": "aa2a0675de682cbc",  
"name": "Cancel Delay",  
"props": [  
{  
"p": "payload"  
},  
{  
"p": "topic",  
"vt": "str"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": false,  
"onceDelay": 0.1,  
"topic": "",  
"payload": "",  
"payloadType": "date",  
"x": 130,  
"y": 320,  
"wires": [  
[  
"e66ae0ac72899773"  
]  
]  
},  
{  
"id": "78ab1eb439ec1abc",  
"type": "comment",  
"z": "aa2a0675de682cbc",  
"name": "This fails",  
"info": "This fails setting msg.reset=true from within a subflow",  
"x": 80,  
"y": 260,  
"wires":   
},  
{  
"id": "e66ae0ac72899773",  
"type": "subflow:5000652e2e0639f2",  
"z": "aa2a0675de682cbc",  
"name": "",  
"x": 350,  
"y": 320,  
"wires":   
}  
]  
...

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:12 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/6 "2023-01-05T18:12:01Z")

</div>

Test Msg Cancel flow  
...  
[  
{  
"id": "5000652e2e0639f2",  
"type": "subflow",  
"name": "Cancel Delay Failure",  
"info": "",  
"category": "",  
"in": [  
{  
"x": 180,  
"y": 140,  
"wires": [  
{  
"id": "93e904b826c5b927"  
}  
]  
}  
],  
"out": ,  
"env": ,  
"meta": {},  
"color": "#DDAA99"  
},  
{  
"id": "ca1fc825888ca8ad",  
"type": "subflow:93d1b74d61d4f90f",  
"z": "5000652e2e0639f2",  
"name": "",  
"x": 520,  
"y": 140,  
"wires":   
},  
{  
"id": "93e904b826c5b927",  
"type": "change",  
"z": "5000652e2e0639f2",  
"name": "",  
"rules": [  
{  
"t": "set",  
"p": "reset",  
"pt": "msg",  
"to": "true",  
"tot": "bool"  
}  
],  
"action": "",  
"property": "",  
"from": "",  
"to": "",  
"reg": false,  
"x": 320,  
"y": 140,  
"wires": [  
[  
"ca1fc825888ca8ad"  
]  
]  
},  
{  
"id": "93d1b74d61d4f90f",  
"type": "subflow",  
"name": "TestMsgCancel",  
"info": "",  
"category": "",  
"in": [  
{  
"x": 80,  
"y": 100,  
"wires": [  
{  
"id": "8e95cef841af3afe"  
},  
{  
"id": "1b3f56701316f785"  
}  
]  
}  
],  
"out": ,  
"env": ,  
"meta": {},  
"color": "#DDAA99"  
},  
{  
"id": "8e95cef841af3afe",  
"type": "delay",  
"z": "93d1b74d61d4f90f",  
"name": "",  
"pauseType": "delay",  
"timeout": "5",  
"timeoutUnits": "seconds",  
"rate": "1",  
"nbRateUnits": "1",  
"rateUnits": "second",  
"randomFirst": "1",  
"randomLast": "5",  
"randomUnits": "seconds",  
"drop": false,  
"allowrate": false,  
"outputs": 1,  
"x": 280,  
"y": 100,  
"wires": [  
[  
"f8bc75fb8ecb0338"  
]  
]  
},  
{  
"id": "f8bc75fb8ecb0338",  
"type": "debug",  
"z": "93d1b74d61d4f90f",  
"name": "",  
"active": true,  
"tosidebar": true,  
"console": false,  
"tostatus": false,  
"complete": ""delay finished"",  
"targetType": "jsonata",  
"statusVal": "",  
"statusType": "auto",  
"x": 480,  
"y": 100,  
"wires":   
},  
{  
"id": "1b3f56701316f785",  
"type": "debug",  
"z": "93d1b74d61d4f90f",  
"name": "",  
"active": true,  
"tosidebar": true,  
"console": false,  
"tostatus": false,  
"complete": "true",  
"targetType": "full",  
"statusVal": "",  
"statusType": "auto",  
"x": 270,  
"y": 40,  
"wires":   
},  
{  
"id": "aa2a0675de682cbc",  
"type": "tab",  
"label": "Cancel Delay Works",  
"disabled": false,  
"info": "",  
"env":   
},  
{  
"id": "e8c53ad359599fe8",  
"type": "inject",  
"z": "aa2a0675de682cbc",  
"name": "Set Delay",  
"props": [  
{  
"p": "payload"  
},  
{  
"p": "topic",  
"vt": "str"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": false,  
"onceDelay": 0.1,  
"topic": "",  
"payload": "",  
"payloadType": "date",  
"x": 120,  
"y": 140,  
"wires": [  
[  
"d04e986cf42f4425"  
]  
]  
},  
{  
"id": "77bd611303adafee",  
"type": "inject",  
"z": "aa2a0675de682cbc",  
"name": "Cancel Delay",  
"props": [  
{  
"p": "reset",  
"v": "true",  
"vt": "bool"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": false,  
"onceDelay": 0.1,  
"topic": "",  
"x": 130,  
"y": 180,  
"wires": [  
[  
"d04e986cf42f4425"  
]  
]  
},  
{  
"id": "d04e986cf42f4425",  
"type": "subflow:93d1b74d61d4f90f",  
"z": "aa2a0675de682cbc",  
"name": "",  
"x": 340,  
"y": 140,  
"wires":   
},  
{  
"id": "3433a4566b875615",  
"type": "comment",  
"z": "aa2a0675de682cbc",  
"name": "This works",  
"info": "This works setting msg.reset=true from within a flow",  
"x": 80,  
"y": 80,  
"wires":   
},  
{  
"id": "1c1812546a3e8f75",  
"type": "inject",  
"z": "aa2a0675de682cbc",  
"name": "Cancel Delay",  
"props": [  
{  
"p": "payload"  
},  
{  
"p": "topic",  
"vt": "str"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": false,  
"onceDelay": 0.1,  
"topic": "",  
"payload": "",  
"payloadType": "date",  
"x": 130,  
"y": 320,  
"wires": [  
[  
"e66ae0ac72899773"  
]  
]  
},  
{  
"id": "78ab1eb439ec1abc",  
"type": "comment",  
"z": "aa2a0675de682cbc",  
"name": "This fails",  
"info": "This fails setting msg.reset=true from within a subflow",  
"x": 80,  
"y": 260,  
"wires":   
},  
{  
"id": "e66ae0ac72899773",  
"type": "subflow:5000652e2e0639f2",  
"z": "aa2a0675de682cbc",  
"name": "",  
"x": 350,  
"y": 320,  
"wires":   
}  
]  
...

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:12 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/7 "2023-01-05T18:12:36Z")

</div>

Cancel Delay Failure flow

```auto
[
    {
        "id": "5000652e2e0639f2",
        "type": "subflow",
        "name": "Cancel Delay Failure",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 140,
                "wires": [
                    {
                        "id": "93e904b826c5b927"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "ca1fc825888ca8ad",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "5000652e2e0639f2",
        "name": "",
        "x": 520,
        "y": 140,
        "wires": []
    },
    {
        "id": "93e904b826c5b927",
        "type": "change",
        "z": "5000652e2e0639f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 140,
        "wires": [
            [
                "ca1fc825888ca8ad"
            ]
        ]
    },
    {
        "id": "93d1b74d61d4f90f",
        "type": "subflow",
        "name": "TestMsgCancel",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 80,
                "y": 100,
                "wires": [
                    {
                        "id": "8e95cef841af3afe"
                    },
                    {
                        "id": "1b3f56701316f785"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8e95cef841af3afe",
        "type": "delay",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 280,
        "y": 100,
        "wires": [
            [
                "f8bc75fb8ecb0338"
            ]
        ]
    },
    {
        "id": "f8bc75fb8ecb0338",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "\"delay finished\"",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 100,
        "wires": []
    },
    {
        "id": "1b3f56701316f785",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "aa2a0675de682cbc",
        "type": "tab",
        "label": "Cancel Delay Works",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e8c53ad359599fe8",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Set Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "77bd611303adafee",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "d04e986cf42f4425",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 340,
        "y": 140,
        "wires": []
    },
    {
        "id": "3433a4566b875615",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This works",
        "info": "This works setting msg.reset=true from within a flow",
        "x": 80,
        "y": 80,
        "wires": []
    },
    {
        "id": "1c1812546a3e8f75",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e66ae0ac72899773"
            ]
        ]
    },
    {
        "id": "78ab1eb439ec1abc",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This fails",
        "info": "This fails setting msg.reset=true from within a subflow",
        "x": 80,
        "y": 260,
        "wires": []
    },
    {
        "id": "e66ae0ac72899773",
        "type": "subflow:5000652e2e0639f2",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 350,
        "y": 320,
        "wires": []
    }
]

```

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 January 2023 18:14 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/8 "2023-01-05T18:14:10Z")

</div>

Backtick (`) not single quote (') 😅

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:18 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/11 "2023-01-05T18:18:05Z")

</div>

Test Msg Cancel

```auto
[
    {
        "id": "5000652e2e0639f2",
        "type": "subflow",
        "name": "Cancel Delay Failure",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 140,
                "wires": [
                    {
                        "id": "93e904b826c5b927"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "ca1fc825888ca8ad",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "5000652e2e0639f2",
        "name": "",
        "x": 520,
        "y": 140,
        "wires": []
    },
    {
        "id": "93e904b826c5b927",
        "type": "change",
        "z": "5000652e2e0639f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 140,
        "wires": [
            [
                "ca1fc825888ca8ad"
            ]
        ]
    },
    {
        "id": "93d1b74d61d4f90f",
        "type": "subflow",
        "name": "TestMsgCancel",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 80,
                "y": 100,
                "wires": [
                    {
                        "id": "8e95cef841af3afe"
                    },
                    {
                        "id": "1b3f56701316f785"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8e95cef841af3afe",
        "type": "delay",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 280,
        "y": 100,
        "wires": [
            [
                "f8bc75fb8ecb0338"
            ]
        ]
    },
    {
        "id": "f8bc75fb8ecb0338",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "\"delay finished\"",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 100,
        "wires": []
    },
    {
        "id": "1b3f56701316f785",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "aa2a0675de682cbc",
        "type": "tab",
        "label": "Cancel Delay Works",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e8c53ad359599fe8",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Set Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "77bd611303adafee",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "d04e986cf42f4425",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 340,
        "y": 140,
        "wires": []
    },
    {
        "id": "3433a4566b875615",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This works",
        "info": "This works setting msg.reset=true from within a flow",
        "x": 80,
        "y": 80,
        "wires": []
    },
    {
        "id": "1c1812546a3e8f75",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e66ae0ac72899773"
            ]
        ]
    },
    {
        "id": "78ab1eb439ec1abc",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This fails",
        "info": "This fails setting msg.reset=true from within a subflow",
        "x": 80,
        "y": 260,
        "wires": []
    },
    {
        "id": "e66ae0ac72899773",
        "type": "subflow:5000652e2e0639f2",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 350,
        "y": 320,
        "wires": []
    }
]

```

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:18 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/12 "2023-01-05T18:18:41Z")

</div>

Cancel Delay Failure

```auto
[
    {
        "id": "5000652e2e0639f2",
        "type": "subflow",
        "name": "Cancel Delay Failure",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 140,
                "wires": [
                    {
                        "id": "93e904b826c5b927"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "ca1fc825888ca8ad",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "5000652e2e0639f2",
        "name": "",
        "x": 520,
        "y": 140,
        "wires": []
    },
    {
        "id": "93e904b826c5b927",
        "type": "change",
        "z": "5000652e2e0639f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 140,
        "wires": [
            [
                "ca1fc825888ca8ad"
            ]
        ]
    },
    {
        "id": "93d1b74d61d4f90f",
        "type": "subflow",
        "name": "TestMsgCancel",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 80,
                "y": 100,
                "wires": [
                    {
                        "id": "8e95cef841af3afe"
                    },
                    {
                        "id": "1b3f56701316f785"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8e95cef841af3afe",
        "type": "delay",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 280,
        "y": 100,
        "wires": [
            [
                "f8bc75fb8ecb0338"
            ]
        ]
    },
    {
        "id": "f8bc75fb8ecb0338",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "\"delay finished\"",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 100,
        "wires": []
    },
    {
        "id": "1b3f56701316f785",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "aa2a0675de682cbc",
        "type": "tab",
        "label": "Cancel Delay Works",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e8c53ad359599fe8",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Set Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "77bd611303adafee",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "d04e986cf42f4425",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 340,
        "y": 140,
        "wires": []
    },
    {
        "id": "3433a4566b875615",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This works",
        "info": "This works setting msg.reset=true from within a flow",
        "x": 80,
        "y": 80,
        "wires": []
    },
    {
        "id": "1c1812546a3e8f75",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e66ae0ac72899773"
            ]
        ]
    },
    {
        "id": "78ab1eb439ec1abc",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This fails",
        "info": "This fails setting msg.reset=true from within a subflow",
        "x": 80,
        "y": 260,
        "wires": []
    },
    {
        "id": "e66ae0ac72899773",
        "type": "subflow:5000652e2e0639f2",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 350,
        "y": 320,
        "wires": []
    }
]

```

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 January 2023 18:23 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/13 "2023-01-05T18:23:01Z")

</div>

Ok,

I see the problem.  
A subflow is not a `singleton`

every subflow that is deployed is a new instance of the subflow.

Therefore `Cancel Delay Failure` fires up its own instance of `TestMsgCancel`

think of a subflow as a blueprint - not a single instance of something

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 January 2023 18:34 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/14 "2023-01-05T18:34:45Z")

</div>

![Screenshot 2023-01-05 at 18.32.54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/748b24edd3bedf72145dc61a429fcf5242af7263.png)

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:53 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/15 "2023-01-05T18:53:24Z")

</div>

If you press the set delay inject you'll see the delay is executed then the msg appears.  
If you press the set delay under This Works then press the cancel delay you'll see the test subflow is invoked but the delay is cancelled and the msg after the delay does not appear.  
If you press the set delay then the Cancel Delay under the This Fails you'll see the test subflow is invoked, the delay is executed, i.e., not cancelled, and the msg after the delay is executed

If you look inside the Cancel Delay Failure it sends the msg with reset=true to the TestMsgCancel subflow

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [5 January 2023 18:57 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/16 "2023-01-05T18:57:18Z")

</div>

So does that mean a delay initiated in any subflow can never be cancelled?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 January 2023 19:08 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/17 "2023-01-05T19:08:45Z")

</div>

> So does that mean a delay initiated in any subflow can never be cancelled?

If you wish to void a delay that is inside a subflow - then you must send the reset property to that (instance) of the subflow (or more accurately the delay node that is inside that subflow instance)

This is why your first one works - you are addressing the same subflow instance.

Each subflow has its own context - it does not share the context of its self globally

> If you look inside the Cancel Delay Failure it sends the msg with reset=true to the TestMsgCancel subflow

Yes - but it is its own copy (or instance) of `TestMsgCancel` Therefore is not making any difference to the instance of `TestMsgCancel` that is in your main flow.

Like I said here

> [@Msg.reset inside subflow not working on delay](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/13):
>
> Ok, I see the problem. A subflow is not a singleton every subflow that is deployed is a new instance of the subflow. Therefore Cancel Delay Failure fires up its own instance of TestMsgCancel think of a subflow as a blueprint - not a single instance of something

A subflow is not a singleton - every copy of your subflow In your main flow, has its own context and environment

---

<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: [5 January 2023 23:18 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/18 "2023-01-05T23:18:26Z")

</div>

If you do want something like a singleton then maybe the link-call node and return is an option .

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [6 January 2023 18:35 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/19 "2023-01-06T18:35:06Z")

</div>

What is the best approach to doing this? Saving the original msg that invoked the subglow with the delay into a global var so it can be sent again to that same subflow with the reset=true? Does that send the msg to the same instance of that subflow?

If there is no easy way to do this I can always just use a global flag to tell the delayshutoff subflow whether to actually do the shut off.

---

<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: [6 January 2023 19:06 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/20 "2023-01-06T19:06:07Z")

</div>

You could use link-call nodes as suggested. That way there is only 1 set of nodes being operated on.

---

<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: [6 January 2023 21:55 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/21 "2023-01-06T21:55:34Z")

</div>

> [@rpoole](#):
>
> Does that send the msg to the same instance of that subflow?

I don't understand what you mean by that. Each instance of the subflow is a node that appears in a flow in the editor. To send a message to a particular instance, that message needs to be sent down a wire into the node.

---

<div class="post-metadata">

### Author: ![rpoole](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rpoole](https://discourse.nodered.org/u/rpoole)
#### Post date: [6 January 2023 23:29 UTC](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238/22 "2023-01-06T23:29:29Z")

</div>

I have two flows A and B that both call subflow X. A calls subflow X to do a certain function that entails a delay node that delays 90 minutes. Flow B needs to cancel the delay in subflow X. My understanding is the reason it didn't work the way I first tried it was there are two instances of subflow X - X(A) and X(B). The delay has subflow X(A) stopped waiting for the delay to expire. When flow B tried to cancel it by calling subflow X it was actually sending the msg with reset=true to instance X(B) thus not cancelling the delay in X(A).

So the question was if I saved the message from within X(A) in a global var and then send it to a different instance of X does that actually send the message back to X(A)?

[Next page](https://discourse.nodered.org/t/msg-reset-inside-subflow-not-working-on-delay/73238.md?page=2)
