# Get current scope in scripting

**URL:** <https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686>\
**Category:** General Discussion\
**Created:** [February 2, 2022, 9:35pm UTC](https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686 "2022-02-02T21:35:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 2, 2022, 9:49pm UTC](https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686/2 "2022-02-02T21:49:32Z")

</div>

> [@Getting the context in which a function is running?](https://forum.inductiveautomation.com/t/getting-the-context-in-which-a-function-is-running/33977):
>
> Related to my question the other day - [Using importlib to run any function on the gateway?](http://forum.inductiveautomation.com/t/using-importlib-to-run-any-function-on-the-gateway/33915/10) Now with forms, I like to run a validation on the client side so that the window doesn’t close and the user has a chance to fix their mistakes. And if that validation runs fine, then it sends a message to the gateway to run the actual create script. However, I know it’s not enough to just validate client side, and I should run it on the gateway end as well to be safe in case someone is able to start run…

> [@Best methods for checking script scope](https://forum.inductiveautomation.com/t/best-methods-for-checking-script-scope/30201/2):
>
> Try this: def getScope(): """ Returns: scope (int): 0=Gateway, 1=Client, 2=Designer """ try: if system.util.getSystemFlags() & system.util.CLIENT\_FLAG: location = 1 elif system.util.getSystemFlags() & system.util.DESIGNER\_FLAG: location = 2 except AttributeError: # system.util.getSystemFlags() does not exist in gateway scope location = 0 return location (Source: [Which scope is my code running in?](http://forum.inductiveautomation.com/t/which-scope-is-my-code-running-in/15540/3))

> [@Which scope is my code running in?](https://forum.inductiveautomation.com/t/which-scope-is-my-code-running-in/15540/2):
>
> Hmm. Something like this (untested): from com.inductiveautomation.ignition.common.model import ApplicationScope scope = ApplicationScope.getGlobalScope() if (ApplicationScope.isClient(scope)): ... if (ApplicationScope.isDesigner(scope)): ... if (ApplicationScope.isGateway(scope)): ...

---

_[View the full topic](https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686)._
