# RED.nodes.getNode fails to find node

**URL:** <https://discourse.nodered.org/t/red-nodes-getnode-fails-to-find-node/19235>\
**Category:** General\
**Created:** [16 December 2019 19:17 UTC](https://discourse.nodered.org/t/red-nodes-getnode-fails-to-find-node/19235 "2019-12-16T19:17:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![magothe](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@magothe](https://discourse.nodered.org/u/magothe)\
**Post date:** [16 December 2019 19:17 UTC](https://discourse.nodered.org/t/red-nodes-getnode-fails-to-find-node/19235/1 "2019-12-16T19:17:23Z")

</div>

I have two custom nodes in my flow: an "OccupancyTrigger" node, and a configuration node named "schedule". The OccupancyTrigger node uses schedule to detemine when it should be enabled. I want the schedule node to communicate changes in its state to the OccupancyTrigger node's status.

occupancy\_trigger.js

```auto
module.exports = function(RED) {    
    function OccupancyTrigger(config) {
        RED.nodes.createNode(this, config);
        var node = this;
        node.schedule = RED.nodes.getNode(config.schedule);
        node.schedule.setupStatusReporting(this.id);

```

schedule.js

```auto
node.setupStatusReporting = function(nodeId) {
            node.idsOfNodesToUpdateStatus.push(nodeId);
            if (node.isExpired) {
                node.setNodeExpiredStatus(nodeId);                
            } else if (node.isActive) {
                node.setNodeActiveStatus(nodeId);
            } else {
                node.setNodeInactiveStatus(nodeId);
            }
        }

```

```auto
node.setNodeActiveStatus = function(nodeId) {
            var nodeToSet = RED.nodes.getNode(nodeId);
            if (nodeToSet ) {
                nodeToSet .status({fill: "green", shape: "dot", text: "active"});
            } else {
                node.warn("couldn't find the node!");
            }
        };

```

I have verified that the id of the OccupancyTrigger node is properly being passed into the schedule node, and that it matches the id displayed on my flow, but I always hit my "couldn't find the node!" logic branch. getNode fails me. Any ideas why?

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [17 December 2019 23:45 UTC](https://discourse.nodered.org/t/red-nodes-getnode-fails-to-find-node/19235/2 "2019-12-17T23:45:18Z")

</div>

> [@magothe](#):
>
> Any ideas why?

Hi Chris,

I'm not very sure why this happens, but I '_think_' the OccupancyTrigger node is at this stage not available entirely in the runtime yet. But I might be wrong!

I had a [question](https://discourse.nodered.org/t/red-nodes-getnode-fails-on-windows-10/18069) recently, that was a bit similar to yours. At the end I found that I was calling the `RED.nodes.getNode` a bit too soon, because the node was at the particular moment not fully loaded yet.

Can't you workaround it like this:

```auto
node.schedule.setupStatusReporting(this);

```

and this:

```auto
node.setNodeActiveStatus = function(nodeToSet) {
    nodeToSet.status({fill: "green", shape: "dot", text: "active"});
};

```

Good luck with it!  
Bart

---

<div class="post-metadata">

**Author:** ![magothe](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@magothe](https://discourse.nodered.org/u/magothe)\
**Post date:** [18 December 2019 17:50 UTC](https://discourse.nodered.org/t/red-nodes-getnode-fails-to-find-node/19235/3 "2019-12-18T17:50:07Z")

</div>

Thank you Bart, that's the solution I stumbled upon as well. I'm trying to keep my application as quick and lean as possible, though, so I'm disappointed I can't just pass a simple id as the function parameter. I may keep investigating as time permits and update this thread if I find a better solution.
