# What does context.total mean?

**URL:** <https://discourse.nodered.org/t/what-does-context-total-mean/58997>\
**Category:** General\
**Created:** [25 February 2022 21:18 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997 "2022-02-25T21:18:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [25 February 2022 21:18 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/1 "2022-02-25T21:18:50Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/a/1add2378ad5a528efc1b8630ae10de027d24deff.jpeg)

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27a471f81fde4de804c89a00671b1dc063b50d9b.jpeg)

---

<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:** [25 February 2022 21:31 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/2 "2022-02-25T21:31:30Z")

</div>

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.

---

<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:** [26 February 2022 00:59 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/3 "2022-02-26T00:59:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [26 February 2022 21:18 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/4 "2022-02-26T21:18:42Z")

</div>

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.

---

<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:** [26 February 2022 21:38 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/5 "2022-02-26T21:38:15Z")

</div>

> [@jbudd](#):
>
> I'm not clear what the difference is between creating a property and adding a value to context

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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [26 February 2022 21:47 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/6 "2022-02-26T21:47:19Z")

</div>

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.

---

<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:** [12 March 2022 21:48 UTC](https://discourse.nodered.org/t/what-does-context-total-mean/58997/7 "2022-03-12T21:48:17Z")

</div>

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