# How to access a global variable from the JS function?

**URL:** <https://forums.losant.com/t/how-to-access-a-global-variable-from-the-js-function/5162>\
**Category:** Help\
**Tags:** function-node\
**Created:** [July 20, 2023, 11:30am UTC](https://forums.losant.com/t/how-to-access-a-global-variable-from-the-js-function/5162 "2023-07-20T11:30:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [July 20, 2023, 11:30am UTC](https://forums.losant.com/t/how-to-access-a-global-variable-from-the-js-function/5162/1 "2023-07-20T11:30:59Z")

</div>

Hi there,

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/28a3989e459e87339a37ccb0c3d0701940aaf422.png)

is there some sort of special variable defined in the JS scope that I can use to grab the global variable?

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [July 20, 2023, 12:02pm UTC](https://forums.losant.com/t/how-to-access-a-global-variable-from-the-js-function/5162/2 "2023-07-20T12:02:08Z")

</div>

Your resolved application and workflow globals are always on the initial workflow payload at the property `globals`. In your case, you are setting a “Function Scope Path” of `data.loop` on your Function Node, which limits what is passed in to the node’s scope. Nothing is exposed outside of that.

If you were not setting that property, you could access the globals at `payload.globals`; but if you must set the property, you will first have to copy/move your `globals` into that object you are setting as the Function Node’s scope.

Easiest way to do that is a [Mutate Node](https://docs.losant.com/workflows/logic/mutate/), moving or copying `globals` into `data.loop`.

---

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [July 21, 2023, 9:55am UTC](https://forums.losant.com/t/how-to-access-a-global-variable-from-the-js-function/5162/3 "2023-07-21T09:55:30Z")

</div>

Oh right! I used the second approach that makes sense.  
Cheers.
