# Can someone look at this flow and tell me what is wrong please?

**URL:** <https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154>\
**Category:** General\
**Created:** [14 September 2018 21:01 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154 "2018-09-14T21:01:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:01 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/1 "2018-09-14T21:01:17Z")

</div>

Guys,

I have a flow - 1st part runs once per second and sets a flow variable to Default - i use the moment node for this - this to enable me to use the formatted date time in a logging file.

I then have a 2nd flow that references this - but each time i try and grab it i am getting an undefined message

Can someone have a look at the two bits below and tell me where i am going wrong please ??

`[{"id":"d6dfc259.d5a88","type":"moment","z":"6865126d.1bde1c","name":"Get the Date and time for the log","topic":"","input":"","inputType":"date","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD-MM-YY HH:mm","locale":"en_AU","output":"MyDateTiime","outputType":"flow","outTz":"Australia/Sydney","x":510,"y":240,"wires":[[]]},{"id":"c17c2fbe.8c5de","type":"inject","z":"6865126d.1bde1c","name":"Store Date and Time","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":180,"y":240,"wires":[["d6dfc259.d5a88"]]}]`

Then the 2nd part (in the same flow) where i reference this - this is triggered by an incoming MQTT message

`[{"id":"c27bb157.46dde","type":"debug","z":"6865126d.1bde1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":430,"y":640,"wires":[]},{"id":"c82a1ddf.22956","type":"mqtt in","z":"6865126d.1bde1c","name":"Incoming MQTT from Tank Pump","topic":"Tank_Top_Up_Pump/Tank_Relay/Switch","qos":"2","broker":"e2ed99fb.aa45d8","x":190,"y":640,"wires":[["c27bb157.46dde","99ce6aa4.7369b8"]]},{"id":"99ce6aa4.7369b8","type":"function","z":"6865126d.1bde1c","name":"Log runs to File","func":"var topic = msg.topic;\nif (msg.payload === \"1\") {\n var p = \"On\";\n } \nelse if (msg.payload === \"0\") { \n var p = \"Off\";\n }\nelse var p = \"Unknown\";\n\nvar d = flow.get('MyDateTime') || \"0\";\n\nvar payload = (d + \"Tank Pump is \" + p + \" Topic \" + msg.topic);\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":720,"wires":[["9fda007f.37ac4","9c9c07be.2df6a8"]]},{"id":"9fda007f.37ac4","type":"debug","z":"6865126d.1bde1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":720,"wires":[]},{"id":"9c9c07be.2df6a8","type":"file","z":"6865126d.1bde1c","name":"Log info the file","filename":"/home/pi/logs/Tank_Pump_Run_Stats","appendNewline":true,"createDir":true,"overwriteFile":"false","x":660,"y":680,"wires":[[]]},{"id":"cdb0d4e3.b4da48","type":"inject","z":"6865126d.1bde1c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":700,"wires":[["99ce6aa4.7369b8"]]},{"id":"e2ed99fb.aa45d8","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]`

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0e1126f9d9307896637c2a946477aab861ac592b.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2451b1fee431fa9aea1675711208d7085c2b5d25.png)

If i leave out the || on the flow.get from the context i get an undefined, if i put in the || (as seen in the debug) i get the 0 in the output.

I am therefore concluding that i am not able to access the variable - but do not understand why

Any ideas ??

regards

Craig

---

<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:** [14 September 2018 21:04 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/2 "2018-09-14T21:04:16Z")

</div>

How have you configured your context storage?

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:06 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/3 "2018-09-14T21:06:26Z")

</div>

MY default is to file - as per some info from Andrei earlier in the week (for persistence) on another bit of code i was wirting.

I am (ultimately) wanting to store this variable in RAM and read it back from there - but that would mean then using the named contexts - so i thought just leave it as default (File) for the time being

Craig

p.s. thanks for the quick response

---

<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:** [14 September 2018 21:07 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/4 "2018-09-14T21:07:35Z")

</div>

Can you share you exact contextStorage setting?

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:09 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/5 "2018-09-14T21:09:02Z")

</div>

Yep here it is - cut and paste straight out of the file

contextStorage: {  
default: {  
module: "localfilesystem"  
},  
memoryOnly: {  
module: "memory"  
}  
}

---

<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:** [14 September 2018 21:10 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/6 "2018-09-14T21:10:29Z")

</div>

The first flow you've shared only has the Inject and Moment nodes - I don't see it doing anything with context.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:12 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/7 "2018-09-14T21:12:09Z")

</div>

Here is a screenshot of the moment node

In the dropdown for storage i have chosen the default (not memory)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/ac5ebb43989491193d6aa239bbbaa7341baa466d.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:16 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/8 "2018-09-14T21:16:50Z")

</div>

And it seems to be working to set it as the info window on context is updating

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cc20e0784fb176fa7b248dcb8c9471052f359084.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:** [14 September 2018 21:18 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/9 "2018-09-14T21:18:47Z")

</div>

Ah - I don't have the Moment node installed, so didn't see that. I wasn't aware it let you output to context directly.

Looking at its source - this is a bug with the Moment node; it needs to be updated to handle the persistent context work. That said, there may be more we can do in the core to make it a bit more transparent to the node - will look at that for 0.19.4.

So don't have a quick resolution for you.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:19 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/10 "2018-09-14T21:19:24Z")

</div>

Sorry - i have just looked at the raw flow - i have a typo there are two ii in the MyDateTime

Almost impossible to see in the visual editor - just picked it up in the raw flow

I am SO SORRY for wasting your VERY VERY valuable time - Nick

regards

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:21 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/11 "2018-09-14T21:21:29Z")

</div>

And just tested and works Ok now - i have spent about 3 hours going backwards and forwards trying to work out what was going on !!!

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:22 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/12 "2018-09-14T21:22:31Z")

</div>

Nick,

The moment node seems fine - it has the option in the dropdown to store to default or memory only (have not tried that yet) - will do so a little later today and report back

Craig

---

<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:** [14 September 2018 21:24 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/13 "2018-09-14T21:24:26Z")

</div>

Hmm, ok - I'm curious where the `#:(memoryOnly)::CurrentDateTiime` entry has come from - the `#:(memoryOnly)::` prefix is an internal thing that shouldn't appear.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:27 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/14 "2018-09-14T21:27:29Z")

</div>

In my screenshot you mean ? That was me choosing it the first time i tried i.e. i thought i would store it to memory only rather than disk each second,

then when that did not work i decided to use the default incase i was doing something wrong and then finally i tried a different name in case i was hitting a reserved word etc

Out of instance - how do i clear those file entries from showing up in the debug/info window - they are redundant/not needed - so what is best practice to clear them up and delete the disk files ? i.e. is there a Delete/remove function ?

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:28 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/15 "2018-09-14T21:28:51Z")

</div>

I did update that moment node a little while ago.

I am also running on Node.js 10.10 - not sure if that would have any effect

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [14 September 2018 21:34 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/16 "2018-09-14T21:34:30Z")

</div>

Just for the record - i just tried to change the Moment node to store to memoryOnly - that worked and i could see the new variable in memoryonly in the flow context

I then tried to use my function to retrieve it - used the name store as per the example below and put in memory (which is what is in my settings.js) and also tried memory.Only as that is what shows in the context browser - neither worked

```auto
var myCount = flow.get("count", storeName);

```

craig

---

<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:** [14 September 2018 21:49 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/17 "2018-09-14T21:49:46Z")

</div>

What exactly can you see in flow context?

If it has some form of `#:(....)::` at the front, then that's broken and will change in 0.19.4.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 September 2018 22:39 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/18 "2018-09-14T22:39:48Z")

</div>

Only just scanned this thread. Does the moment node need updating? If so, any clues - or even a PR would be nice 😉 but I'll endeavour to sort if needed.

---

<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:** [14 September 2018 23:05 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/19 "2018-09-14T23:05:27Z")

</div>

On reflection, this is on oversight on our part.

Whilst you could make some changes to handle multiple context stores properly, it is better for us to handle it for you. I've already pushed a fix to git and 0.19.4 will resolve it.

Appreciate that doesn't really get into the fine details of the issue, but it's late. Happy to share more details another time if anyone is interested.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [15 September 2018 01:47 UTC](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154/20 "2018-09-15T01:47:40Z")

</div>

Nick,

Here is what it looks like in the debug window

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7d3d8553b45c9e87c054842a280ba041554e637f.png)

regards

Craig

[Next page](https://discourse.nodered.org/t/can-someone-look-at-this-flow-and-tell-me-what-is-wrong-please/3154.md?page=2)
