# Changing global variables in a JS function

**URL:** <https://forums.losant.com/t/changing-global-variables-in-a-js-function/501>\
**Category:** Help\
**Created:** [May 23, 2017, 1:07pm UTC](https://forums.losant.com/t/changing-global-variables-in-a-js-function/501 "2017-05-23T13:07:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsierkstra](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@hsierkstra](https://forums.losant.com/u/hsierkstra)\
**Post date:** [May 23, 2017, 1:07pm UTC](https://forums.losant.com/t/changing-global-variables-in-a-js-function/501/1 "2017-05-23T13:07:17Z")

</div>

Hi guys,

I’m trying to include some extra functionality in my workflows, but I’m not finding a lot of ways to act on a device-independent state of the system. Using global variables could be a way to come around this, but they are not so easily managed. Above all they are workflow-specific, and they cannot be viewed or edited through a dashboard (to my knowledge). I’m trying to figure out the best way to do this, maybe I should create a new device to keep states.

A specific problem I’m experiencing now is that I can’t seem to mutate the values of global variables in JavaScript ‘function’ blocks in my workflows. What’s the best way to do this?

---

<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:** [May 23, 2017, 1:33pm UTC](https://forums.losant.com/t/changing-global-variables-in-a-js-function/501/2 "2017-05-23T13:33:27Z")

</div>

Without knowing much about your use case, our best recommendation is to use [Store Value](https://docs.losant.com/workflows/data/store-value/) and [Get Value](https://docs.losant.com/workflows/data/get-value/) nodes. These allow you to set a value during a workflow run and use that value in a subsequent run. We think of workflow globals as constants – things such as third-party API credentials and other values that should never change between runs.

Please let us know if those two nodes provide the functionality you’re looking for!

---

<div class="post-metadata">

**Author:** ![hsierkstra](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@hsierkstra](https://forums.losant.com/u/hsierkstra)\
**Post date:** [May 23, 2017, 1:54pm UTC](https://forums.losant.com/t/changing-global-variables-in-a-js-function/501/3 "2017-05-23T13:54:25Z")

</div>

Hey,

Thanks for pointing out how global variables were intended. I was probably right thinking this was not the way to go 😉 Store and Get may be just fine here, I’ll see how far it takes me. Thanks again!
