What does context.total mean?

In this simple flow, context.total holds a running total of msg.payload, yet there is no context.get or context.set.

The debug panel Context Data shows empty for the Function node and the Flow.

So what exactly is context.total and how does it retain data over several messages?
Am I creating a global variable that just happens to have a dot in it's name?

Untitled 2

You are creating a property of the context object itself.

That is different to adding a value to context using set.

This is a valid way of predefining variables in the on start tab of the Function node and accessing them in the on message code, without going to the extent of storing inside context itself.

1 Like

While valid, it does not access any of the optional storage plugins so will only ever be in memory context and not persisted over restarts.

Thanks both.

I'm not clear what the difference is between creating a property and adding a value to context but never mind.

So far I have not found a need for on start or persistant storage but I will continue using context.[gs]et even though it looks clunky in comparison.

One is setting a property on an object, the other is a function call. The function can handle alternative context stores such as file backed.

I'm sorry, I should have said I'm not clear how the data structure "context" is different following the two ways of manipulating it.

I guess I would have expected the data structure to be private to the object, only externally visible through the public methods.

No doubt you can tell I am not very familiar with object oriented programming.

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