# Jsonata in global environment variables with reference

**URL:** <https://discourse.nodered.org/t/jsonata-in-global-environment-variables-with-reference/81927>\
**Category:** General\
**Created:** [10 October 2023 15:37 UTC](https://discourse.nodered.org/t/jsonata-in-global-environment-variables-with-reference/81927 "2023-10-10T15:37:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IotDeveloper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotdeveloper/32/75870_2.png) [@IotDeveloper](https://discourse.nodered.org/u/IotDeveloper)\
**Post date:** [10 October 2023 15:37 UTC](https://discourse.nodered.org/t/jsonata-in-global-environment-variables-with-reference/81927/1 "2023-10-10T15:37:39Z")

</div>

Hello,

i want to use jsonata expression within the released function "Global Environment Variables".  
The jsonata contains a logical function, which checks if a environmental variable exists. If not, it sets a default value, which is also stored within the Global Environment Variables section. I had trouble getting this to work. Therefore i decided to shorten the jsonata and observed that there is a functional difference between flow and global environmental section.

It seems, that i can´t reference inside a variable within the "Global Environent Variables" section.

Here is an example:

1. In the global env section "globEnvWriteTopic" references "defWriteTopic"
2. Reference the "globEnvWriteTopic" in an inject node
3. Payload is empty

It works, if i´m using this reference in the flow section.

Is that an issue of the new release?

Best regards,

Martin

 ![23-10-10_17-24#0005](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/121c17d24c9a8b1e9e9ea623174d40ad321cf157.jpeg)

---

<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:** [10 October 2023 15:52 UTC](https://discourse.nodered.org/t/jsonata-in-global-environment-variables-with-reference/81927/2 "2023-10-10T15:52:25Z")

</div>

Variables are not surrounded by quotes. If you wanted to reference a env var then the $env($env("varname")) would be more correct.

The order you create them in the Global env variable editor may be of importance to.

---

<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:** [9 December 2023 15:52 UTC](https://discourse.nodered.org/t/jsonata-in-global-environment-variables-with-reference/81927/3 "2023-12-09T15:52:45Z")

</div>

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