# Keep contents of multiple change nodes synchronised

**URL:** https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018
**Category:** General
**Created:** [7 June 2023 12:36 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018 "2023-06-07T12:36:53Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [7 June 2023 12:36 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/1 "2023-06-07T12:36:53Z")

</div>

Is it possible to synchronize the contents of a node across multiple flows?  
I'm using a change node to change one part of a message that can come in from multiple http endpoints and each endpoint has it's own separate work flow.  
My thought is maybe to use a stored file and function node so that I only have to edit the one file instead of four change nodes.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 June 2023 12:42 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/2 "2023-06-07T12:42:48Z")

</div>

Store the contents in a global [context](https://nodered.org/docs/user-guide/context) variable, then have all change nodes read the global variable.

---

<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: [7 June 2023 12:49 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/3 "2023-06-07T12:49:48Z")

</div>

Or use Link Call nodes to run the common code in one flow.

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [7 June 2023 12:54 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/4 "2023-06-07T12:54:21Z")

</div>

I thought of using link nodes but each flow has it's own workflow and needs to be seperate.

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [7 June 2023 12:58 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/5 "2023-06-07T12:58:25Z")

</div>

Each change node has multiple of the following:  
Change - msg.site - Search for xyz and replace with zyx

I think I need to move away from the change node and into something custom to achieve what I'm looking for.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 June 2023 13:03 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/6 "2023-06-07T13:03:07Z")

</div>

Difficult to give examples when you do not share enough info, but you could do all the search and replace in change node with JSONata and then save to context. Really need to see a example of what you are doing.

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [7 June 2023 13:09 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/7 "2023-06-07T13:09:08Z")

</div>

```auto
[{"id":"25997d3c0fa37a57","type":"change","z":"d03c03b6d2f91f47","name":"Change Serial To Site","rules":[{"t":"change","p":"site","pt":"msg","from":"123456789","fromt":"str","to":"Site_845","tot":"str"},{"t":"change","p":"site","pt":"msg","from":"123456799","fromt":"str","to":"Site_855","tot":"str"},{"t":"change","p":"site","pt":"msg","from":"12585978","fromt":"str","to":"Site_865","tot":"str"},{"t":"change","p":"site","pt":"msg","from":"123789456","fromt":"str","to":"Site_875","tot":"str"},{"t":"change","p":"site","pt":"msg","from":"132456789","fromt":"str","to":"Site_885","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"site","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1200,"wires":[[]]}]

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 June 2023 13:56 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/8 "2023-06-07T13:56:15Z")

</div>

Setting all sites in global sites

Then in each change node you can use  
set `msg.` `topic`  
to value of `global.` `sites[msg.site]`  
e.g.

```auto
[{"id":"e97fe89bc18cc3e9","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"site","v":"12345","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":4080,"wires":[["e62ab11ec7c1750a"]]},{"id":"e62ab11ec7c1750a","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"sites[msg.site]","tot":"global"},{"t":"set","p":"payload","pt":"msg","to":"sites[msg.site]","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":4100,"wires":[["fee79774d31c98c4"]]},{"id":"5ae1e20717632d23","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"site","v":"12346","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":4140,"wires":[["e62ab11ec7c1750a"]]},{"id":"fee79774d31c98c4","type":"debug","z":"b9860b4b9de8c8da","name":"debug 307","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":4080,"wires":[]},{"id":"e477268b9da7d96c","type":"inject","z":"b9860b4b9de8c8da","name":"set global sites","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":3980,"wires":[["25997d3c0fa37a57"]]},{"id":"25997d3c0fa37a57","type":"change","z":"b9860b4b9de8c8da","name":"gloabl sites","rules":[{"t":"set","p":"sites","pt":"global","to":"{\t \"12345\": \"site1\",\t \"12346\": \"site2\"\t}\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3980,"wires":[[]]}]

```

Then you only need to edit the global to make changes.

Still a guess as we have no idea the value and format of msg.site.

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [7 June 2023 14:15 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/9 "2023-06-07T14:15:36Z")

</div>

Very cool. Thanks for that.

---

<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: [21 June 2023 14:16 UTC](https://discourse.nodered.org/t/keep-contents-of-multiple-change-nodes-synchronised/79018/10 "2023-06-21T14:16:00Z")

</div>

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