# \[Feature Request\]Set flow context directly in inject node

**URL:** <https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299>\
**Category:** Feature Requests\
**Created:** [20 November 2024 20:59 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299 "2024-11-20T20:59:58Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [20 November 2024 20:59 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/1 "2024-11-20T20:59:58Z")

</div>

Instead of having to set msg properties

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/068af41651a4c7fba6afdfba05f1c15ed9090cb7.png)

and then having to convert them to flow properties

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0f840ed536c05a9b259cd9129f0831d3acff1338.png)

Could we have option to set all the contexts (msg/flow/global) in the inject node please?

---

<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:** [20 November 2024 21:10 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/2 "2024-11-20T21:10:32Z")

</div>

Do you mean have the Inject node write directly to context, rather than send a message?

---

<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:** [20 November 2024 21:12 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/3 "2024-11-20T21:12:54Z")

</div>

Yes please - that's what I was after

---

<div class="post-metadata">

**Author:** ![sammachin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sammachin/32/5121_2.png) [@sammachin](https://discourse.nodered.org/u/sammachin)\
**Post date:** [21 November 2024 08:23 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/4 "2024-11-21T08:23:15Z")

</div>

+1 for this, although I think the inject node should always send a msg object even if its an empty one (if only flow/global is set) just for consistency.

---

<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:** [21 November 2024 08:26 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/5 "2024-11-21T08:26:36Z")

</div>

Just tested and it already does that if nothing is specified in the node

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

---

<div class="post-metadata">

**Author:** ![sammachin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sammachin/32/5121_2.png) [@sammachin](https://discourse.nodered.org/u/sammachin)\
**Post date:** [21 November 2024 08:29 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/6 "2024-11-21T08:29:27Z")

</div>

Yes what I mean was if only setting flow/global contexts it should continue to do that rather than not sending a message

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 November 2024 09:21 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/7 "2024-11-21T09:21:11Z")

</div>

I would also like to see that option in the inject node.

---

<div class="post-metadata">

**Author:** ![RvG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rvg/32/96613_2.png) [@RvG](https://discourse.nodered.org/u/RvG)\
**Post date:** [21 November 2024 09:58 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/8 "2024-11-21T09:58:41Z")

</div>

That would clean up some of my flows, but I'm quite used now to have a change node right after the inject node.

In this particular case I would personally use the contrib-credentials node instead of the change node, to prevent storing a password in plain text in the flow.json.

---

<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:** [21 November 2024 10:36 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/9 "2024-11-21T10:36:55Z")

</div>

> [@cymplecy](#):
>
> Could we have option to set all the contexts (msg/flow/global) in the inject node please?

I am in two minds about this. I can see the advantage where context needs to be initialised, but I don't like nodes with side effects not visible from the flows image. If one sees an Inject node with nothing connected one would likely assume that it is doing nothing, which would not be the case.

Of course I am biased in that I think global and flow context are often overused and should be discouraged except for the few occasions where there is a clear advantage to using context.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [21 November 2024 10:54 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/10 "2024-11-21T10:54:06Z")

</div>

If ever then it needs to be somehow configurable to override/not override possibly existing thing in context.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 November 2024 11:59 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/11 "2024-11-21T11:59:41Z")

</div>

> [@Colin](#):
>
> If one sees an Inject node with nothing connected one would likely assume that it is doing nothing,

This ^

I too am not keen on this request TBH.  
It is somewhat anti pattern and veers off the (usual goal of) do one thing and do it well.

To play devil advocate for a moment, something I _often_ do is setup an inject node, get everything working nicely, then have to recreate it as a change node when I want to "wire it up in an automation". For me, a far better FR would be the ability to convert an inject node to change node or the ability to copy rows from the inject and paste them into a change node.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 November 2024 12:15 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/12 "2024-11-21T12:15:30Z")

</div>

> [@Steve-Mcl](#):
>
> I too am not keen on this request TBH.

Me neither, what happens if the inject node is repetitive and continual updates the context? Try debugging that ...

If you don't have a debug hanging from the inject and without explicitly opening the inject node, you won't know what was updating your context.

> [@Steve-Mcl](#):
>
> veers off the (usual goal of) do one thing and do it well.

Do one thing and one thing only, with every new thing, there is an exponential increase in errors ==\> (all present features) x (in combination with new feature).

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [21 November 2024 15:07 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/13 "2024-11-21T15:07:06Z")

</div>

> [@Steve-Mcl](#):
>
> recreate it as a change node

or simply put an input port to the inject node and wire it from behind ?  
like a cronplus node has an inject button as well as can be triggered from behind  
best of both worlds?  
_unless there is a strong reason for NOT PUTTING an input port on an inject node_

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9bd853788da82cc528365cb77211546a61c9f867.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 November 2024 16:14 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/14 "2024-11-21T16:14:11Z")

</div>

> [@smanjunath211](#):
>
> like a cronplus node has an inject button as well as can be triggered from behind  
> best of both worlds?

While I obviously agree (I wrote cron-plus), it doesnt look pretty.

Something I've been swishing around my brain for some time is a redesign of the nodes and button placement that would permit both an input and a button without making Nick an Dave gag 😉

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 November 2024 16:50 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/15 "2024-11-21T16:50:02Z")

</div>

> [@smanjunath211](#):
>
> _unless there is a strong reason for NOT PUTTING an input port on an inject node_

Or put an button on a change node ... perhaps this is a case of merging the change and inject nodes into a injange node!

---

<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:** [22 November 2024 10:07 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/16 "2024-11-22T10:07:09Z")

</div>

> [@Steve-Mcl](#):
>
> permit both an input and a button without making Nick an Dave gag 😉

Good luck with that ! (but will keep an open mind)

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [22 November 2024 23:16 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/17 "2024-11-22T23:16:54Z")

</div>

Normally I've always placed a function node after an inject to set context vars, but I could see this being useful for me as well if it saves time/editor-space.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 November 2024 09:30 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/18 "2024-11-23T09:30:43Z")

</div>

@HaroldPetersInskipp I'm just wondering, why did you use a `function` node and not a `change` node to set the context variable?

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [23 November 2024 10:00 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/19 "2024-11-23T10:00:45Z")

</div>

> [@zenofmud](#):
>
> to set the context variable?

Isn't that just using [`flow` and `global`](https://nodered.org/docs/user-guide/writing-functions#storing-data) objects in the function node?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 November 2024 10:13 UTC](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299/20 "2024-11-23T10:13:42Z")

</div>

With the change node you can set multiple items so you could set multiple flow and or global variables, You can do the same in a function node but you have to create the code and the function node has a little overhead.

So if all you are doing is setting some flow and/or global variables I would choose the change node over the function node.

[Next page](https://discourse.nodered.org/t/feature-request-set-flow-context-directly-in-inject-node/93299.md?page=2)
