# Script Running on Gateway or Client

**URL:** <https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 23, 2020, 10:14pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768 "2020-12-23T22:14:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 23, 2020, 10:14pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768/1 "2020-12-23T22:14:52Z")

</div>

I feel like there is a simple solution for this that I’m missing. Is there a way to detect from within a script if it is currently being executed in the Client vs in a Gateway script? I have a project script module for caching data that I would like to be able to use for both the Client and Gateway but I need to do some redirecting for helper functions depending on the environment the script is running in. (I should add, I am hoping to avoid having to add an extra input variable that I need to manually set wherever I use this script. Would like some way to automatically detect this from within the script if possible.)

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [December 23, 2020, 10:42pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768/2 "2020-12-23T22:42:52Z")

</div>

As far as I understand, in perspective all scripts are run on the gateway. In vision I think that you can use these functions to check:

```auto
def getScope():
	"""gets the scope that the execution is running in and returns a string indication of which scope
	
		Returns: a string indicating with scope the function is executing in
	"""
	from com.inductiveautomation.ignition.common.model import ApplicationScope
	scope = ApplicationScope.getGlobalScope()
	
	if ApplicationScope.isGateway(scope):
		return 'gateway'
	if ApplicationScope.isClient(scope):
		return 'client'
	if ApplicationScope.isDesigner(scope):
		return 'designer'

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 23, 2020, 10:44pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768/3 "2020-12-23T22:44:45Z")

</div>

If you don’t want to rely on an internal Ignition package, you can use [system.util.getSystemFlags()](https://docs.inductiveautomation.com/display/DOC81/system.util.getSystemFlags).

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 23, 2020, 10:50pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768/4 "2020-12-23T22:50:37Z")

</div>

@pturmel I knew there had to be something in system.util, but I glazed right over getSystemFlags(). Exactly what I needed. Thanks!

@chandler Your solution worked great too. Thanks!

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 23, 2020, 10:58pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768/5 "2020-12-23T22:58:46Z")

</div>

Actually I may have spoke too soon. It looks like `system.util.getSystemFlags()` cannot be called from the Gateway scope?

```auto
AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'getSystemFlags'

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 23, 2020, 11:05pm UTC](https://forum.inductiveautomation.com/t/script-running-on-gateway-or-client/41768/6 "2020-12-23T23:05:23Z")

</div>

I would wrap it in a try/except block.
