# Can a node refer to itself using JSONata?

**URL:** <https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500>\
**Category:** General\
**Created:** [16 February 2022 23:42 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500 "2022-02-16T23:42:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PIstonHome](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pistonhome/32/56690_2.png) [@PIstonHome](https://discourse.nodered.org/u/PIstonHome)\
**Post date:** [16 February 2022 23:42 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500/1 "2022-02-16T23:42:45Z")

</div>

With JSONata, am I able to refer to the node itself? See image. I would like the JSONata expression to result in global.foobar. Currently, it is taking the information of the previous payload (msg.data.entity\_id), which I do not need.

[![Imgur](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c8522ded65aa87d0f10abd6d330b58a84a1d2a8.png "Imgur: The magic of the Internet") ](https://imgur.com/bHhscja)

---

<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:** [17 February 2022 00:09 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500/2 "2022-02-17T00:09:01Z")

</div>

No. JSONata expressions do not have access to node properties. They can only access msg properties.

---

<div class="post-metadata">

**Author:** ![PIstonHome](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pistonhome/32/56690_2.png) [@PIstonHome](https://discourse.nodered.org/u/PIstonHome)\
**Post date:** [17 February 2022 15:03 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500/3 "2022-02-17T15:03:03Z")

</div>

Not doubting what you're saying, but I did find how to do it. This was able to refer to the node itself.

$globalContext($substringAfter($entity().entity\_id,"."))

---

<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:** [17 February 2022 15:27 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500/4 "2022-02-17T15:27:09Z")

</div>

Is your node-red the HA addon ?

I ask as the $entity() appears to be jsonata function added by HA

> **[JSONata | node-red-contrib-home-assistant-websocket](https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html)**
>
> Node-RED integration with Home Assistant through the WebSocket and HTTP API

---

<div class="post-metadata">

**Author:** ![PIstonHome](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pistonhome/32/56690_2.png) [@PIstonHome](https://discourse.nodered.org/u/PIstonHome)\
**Post date:** [17 February 2022 15:47 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500/5 "2022-02-17T15:47:11Z")

</div>

It is, yea. Ah gotcha, so not native to NR, but rather added by HA.

---

<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:** [18 April 2022 15:47 UTC](https://discourse.nodered.org/t/can-a-node-refer-to-itself-using-jsonata/58500/6 "2022-04-18T15:47:28Z")

</div>

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