# Can a Change node access its own context?

**URL:** https://discourse.nodered.org/t/can-a-change-node-access-its-own-context/80342
**Category:** General
**Created:** [5 August 2023 22:22 UTC](https://discourse.nodered.org/t/can-a-change-node-access-its-own-context/80342 "2023-08-05T22:22:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AndreKR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrekr/32/81657_2.png) [@AndreKR](https://discourse.nodered.org/u/AndreKR)
#### Post date: [5 August 2023 22:22 UTC](https://discourse.nodered.org/t/can-a-change-node-access-its-own-context/80342/1 "2023-08-05T22:22:20Z")

</div>

In the configuration of the _Change_ node I can access flow and global context by choosing `flow.` or `global.` from the dropdown.

But can it not access its own context? There is no `context.` in the dropdown.

For example I if I want to compare a value with the value from the previous message I could load the value of the previous message from a context field and then put the value from the current message into the context field. There's no need to have this in flow context, node-local context would be sufficient.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [5 August 2023 22:48 UTC](https://discourse.nodered.org/t/can-a-change-node-access-its-own-context/80342/2 "2023-08-05T22:48:25Z")

</div>

I think you may need to use a `function` node for that.

Eg:

```auto
let old = context.get("OLD") || null;
let new = msg.payload;
if (old == new)
{
    // do your stuff here as they are different.
}
else
{
    // They are different
    context.set("old",new);
    return;
}

```

That is a BASIC (and long) version of what I believe you are trying to do.  
Oh, somewhere in there you need to `return msg`.  
I don't know what you want to do so have left that part out.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [6 August 2023 08:14 UTC](https://discourse.nodered.org/t/can-a-change-node-access-its-own-context/80342/3 "2023-08-06T08:14:36Z")

</div>

I and others have raised this feature request in the past and I think Nick is quite happy for someone to come up with a PR to implement it

But it's not a priority for the core team

> [@AndreKR](#):
>
> For example I if I want to compare a value with the value from the previous message

There is this often missed feature in the switch node

> [@\[Feature Request\]Let change nodes access local context](https://discourse.nodered.org/t/feature-request-let-change-nodes-access-local-context/29491/12):
>
> The switch node can already compare to previous value...

---

<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: [20 August 2023 08:14 UTC](https://discourse.nodered.org/t/can-a-change-node-access-its-own-context/80342/4 "2023-08-20T08:14:56Z")

</div>

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