# How to access context in a change node using the J: method

**URL:** <https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241>\
**Category:** General\
**Created:** [28 November 2023 08:40 UTC](https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241 "2023-11-28T08:40:30Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [28 November 2023 08:40 UTC](https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241/1 "2023-11-28T08:40:30Z")

</div>

Sorry, I know I've asked before but it is possible.

I want to do some maths on a context but can't remember how to do that trick.

I seem to remember in the `change` node you set it something like:  
`J: flow.get("something") * 2`  
and that will give me `flow.get("something")` value multiplied by `2`.

But when I'm doing it now, I get `undefined`.

---

<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:** [28 November 2023 08:47 UTC](https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241/2 "2023-11-28T08:47:28Z")

</div>

example / solution.  
`J: $globalContext("SCAN_TIME")`

(Just incase anyone else is interested.)

---

<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:** [28 November 2023 11:13 UTC](https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241/3 "2023-11-28T11:13:46Z")

</div>

Unless you need to do it dynamically, you can just do,  
set `msg.` `var`  
to `global.` `SCAN_TIME`

Only use JSONata if needed as it has overheads.

Just for others info.

---

<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:** [28 November 2023 11:16 UTC](https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241/4 "2023-11-28T11:16:42Z")

</div>

Thanks.

I'm not exactly sure about if that is or not FIXED.... I think most of the time it is, but I need it to be changed in this case dynamically if the global value is changed.....

Then I add a _fudge factor_ to it.

So really it is:  
`J: $globalContext("SCAN_TIME") * 1.5` So there is _wiggle room_ if the timing goes off.

But thanks for the reply.

Oh, and I did it this way to NOT use a `function` node.  
(Though most of the time I shall say I am guilty of doing that. But to keep the memory working I thought it would be nice to do it in a `change` node instead.)  
(Also to explain why I am doing it this way)

---

<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 December 2023 11:17 UTC](https://discourse.nodered.org/t/how-to-access-context-in-a-change-node-using-the-j-method/83241/5 "2023-12-12T11:17:32Z")

</div>

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