Getting the context in which a function is running?

Related to my question the other day - Using importlib to run any function on the gateway?

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 running my modules in a way not intended.

But the validation function is the same no matter the scope what changes is the what it does at the end.

Is there a way to do something like the following:

def validate(...):
    if someCondition:
        raise ValueError("Something wrong")
    .....
   scope = system.someScriptHere()
   if scope == "client":
       system.util.sendMessage(...)
   elif scope == "gateway":
       return 1
1 Like

However you check for scope, consider doing it at the top level of an inherited script module, setting booleans like isDesigner and isGateway. Then just check the booleans everywhere else.

Something like this:

try:
    isDesigner = bool(system.util.getSystemFlags() & system.util.DESIGNER_FLAG)
    isGateway = False
except AttributeError:
    isDesigner = False
    isGateway = True

When you say top level of an inherited script what do you mean? I created a new script module util with one function getScope which is the above function. I was planning on using it by doing

import util
...
scope = util.getScope()

How would I utilize your method?

Don’t import util–not necessary. If you use my example in the util script module, just do this in your validation script module:

def validate(...):
    if someCondition:
        raise ValueError("Something wrong")
    .....
   if util.isGateway:
       return 1
   else:
       return system.util.sendRequest(...)