# How should the change node work with context?

**URL:** <https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058>\
**Category:** General\
**Created:** [3 January 2022 19:31 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058 "2022-01-03T19:31:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 January 2022 19:31 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/1 "2022-01-03T19:31:46Z")

</div>

Using the `change` node to modify several properties of an incoming message, I decided to save the modified message in global context. It took a while to find the trick, but this seems to work.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75490c624cd5e2cbb65634f8ef7abeb1e7bb6d36.png)

But I have questions. Should this even work? Or is it a quirk of the JSONata compatibility mode that will go away someday? Can the `change` node do the reverse, that is retrieve the message from context and send it on? (I haven't found a way, so far.)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [3 January 2022 20:21 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/2 "2022-01-03T20:21:03Z")

</div>

Try setting msg.foo to global.msg0!

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 January 2022 20:39 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/3 "2022-01-03T20:39:43Z")

</div>

Not exactly, but my question wasn't completely clear. That retrieves the old message as a **property** of the incoming message, not as a message itself that can be sent along.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [3 January 2022 20:43 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/4 "2022-01-03T20:43:29Z")

</div>

But all properties are "Sent along" as part of the parent msg.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 January 2022 20:46 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/5 "2022-01-03T20:46:38Z")

</div>

Understood, but what I really want is the equivalent of a function with

```auto
return global.get("msg0");

```

so that I get back exactly the message that I saved in context.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [3 January 2022 20:47 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/6 "2022-01-03T20:47:38Z")

</div>

OK, can I ask why you want to do that?

---

<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:** [3 January 2022 21:01 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/7 "2022-01-03T21:01:43Z")

</div>

Just to answer the original question, the Change cannot set the entire message object. Not an intentional restriction - just never had a requirement to be able to do it.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 January 2022 22:09 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/8 "2022-01-03T22:09:53Z")

</div>

I had forgotten that this has been discussed [before](https://discourse.nodered.org/t/add-a-way-to-create-a-completely-new-object-change-node-enhancement/53167). Clearly, there are some technical issues involved, but there seem to be other users who might like to have the feature.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 January 2022 22:15 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/9 "2022-01-03T22:15:16Z")

</div>

At the moment, I'm just exploring the possibilities. I'm working on a couple of projects involving fairly complex message routing -- distribution, queueing, load balancing, etc. and I'm making a sort of catalogue of the available tools (including my contributed nodes, of course).

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 January 2022 22:23 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/10 "2022-01-03T22:23:35Z")

</div>

Nick, if you don't mind another question, will the configuration in the screenshot continue to work, or does it depend on the compatibility mode for JSONata?

---

<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:** [4 March 2022 22:23 UTC](https://discourse.nodered.org/t/how-should-the-change-node-work-with-context/56058/11 "2022-03-04T22:23:52Z")

</div>

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