# Is there a way to find what is creating/updating globals?

**URL:** <https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473>\
**Category:** General\
**Created:** [16 July 2021 04:20 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473 "2021-07-16T04:20:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [16 July 2021 04:20 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/1 "2021-07-16T04:20:34Z")

</div>

Guys,

Is there a way to find what tab/function is updating a global variable ? i am up to about 40 tabs now and trying to track down where/what is updating a couple of globals is doing my head in !

Craig

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [16 July 2021 04:32 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/2 "2021-07-16T04:32:07Z")

</div>

If you enter global.set in the search field it will give you a list of all nodes including that statement. Thats one way. Another is if you open the flow file in a text editior and search for the same phrase, then you also see "more inside" where it happens so to say

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/a/1aa990d393269c76b954422cc9d795e3bae072df.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [16 July 2021 04:40 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/3 "2021-07-16T04:40:26Z")

</div>

Thanks - Much appreciated - it would be a nice feature in the Debug window/COntext browser to be able to highlight the variable and click on it.

Craig

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 July 2021 09:31 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/4 "2021-07-16T09:31:47Z")

</div>

Just to add that I found I was getting to a similar position, not just with context variables but also MQTT topics. So I started adding a standard function to all updates that add an updated timestamp and an updatedBy which indicates the node-red instance, tab name and roughly what function/node did the update. That way, I don't have to keep searching for things but can see at a glance what updated what.

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/acab7773c63ade43646a060130aefe298bc914dd.png)

---

<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:** [16 July 2021 15:08 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/5 "2021-07-16T15:08:06Z")

</div>

> [@TotallyInformation](#):
>
> I started adding a standard function to all updates that add an updated timestamp and an updatedBy

That sounds like a great idea. Using the new User Properties feature of MQTT 5 I think I should be able to add those as User Properties so avoiding the requirement to modify the payload, which would mess up existing flows.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 July 2021 16:51 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/6 "2021-07-16T16:51:52Z")

</div>

On MQTT, they are extra topics beneath the main topic. I sometimes add them using a function late in the flow.

I typically make my global vars match the structure of my MQTT topics which minimises flow complexity.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [17 July 2021 04:22 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/7 "2021-07-17T04:22:01Z")

</div>

Julian - could you give me an example of a MQTT topic and the corresponding Global that you would use ?

Craig

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 July 2021 11:34 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/8 "2021-07-17T11:34:38Z")

</div>

Here is an extract from the `known_devices` global var showing the same data as my MQTT example:

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

The main difference between MQTT topics and JS objects is that while you _can_ have a value on a parent topic in MQTT (as you see in the wiser topic structure), you can't do that exactly the same on a JS object. So the equivalent object for something like the wiser data (actually I don't happen to keep that as a global var because I just keep the whole wiser object that is updated every minute whereas the mqtt topics shown are useful because they are only updated when necessary) would be something like:

```auto
  ...
  BatteryLevel: {
    value: 'Normal',
    updated: ...,
    updatedBy: ...
  }

```

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [18 July 2021 02:34 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/9 "2021-07-18T02:34:49Z")

</div>

Thanks for this info Julian

Craig

---

<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:** [1 August 2021 02:35 UTC](https://discourse.nodered.org/t/is-there-a-way-to-find-what-is-creating-updating-globals/48473/10 "2021-08-01T02:35:25Z")

</div>

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