Best methods for checking script scope

I am trying to call system.db.runNamedQuery() in a Shared script. I would like to be able to call this from both Project scope (button on a client) as well as Gateway scope (tag change script based on datetime trigger Sunday 11PM).

Similar problem to:

Is there a reliable way to check scoping so that i can do something like:

If scope == Gateway:
   result = system.db.runNamedQuery('projectName','queryName',args)
   result = system.db.runNamedQuery('queryName',args)

A lot of my scripts written in my shared libraries are able to be run from either scope, this is the first time i’ve run into this problem.

Try this:

	def getScope():
			scope (int): 0=Gateway, 1=Client, 2=Designer
			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?)


Thanks Nick,

I have ended up creating a function using the ApplicationScope.getGlobalScope() method which seems to work fine in all scopes.

Yes, that method is probably supported better, good call.