No module named gateway

I’m trying to call a global shared function containing calls to the api from the script console.
I’ve included a screenshot to provide the context.

The function starts with:
‘from com.inductiveautomation.ignition.gateway import SRContext’
When calling the function in the script module, I get an error message that says ‘No module named gateway’
By the way, I get the same error if I try the put the function code directly in the script module.

In contrast, I created a tag which calls this function and the function calls executes properly there.

What am I missing?

You can’t run this in the script console because it’s executing in the Designer in that case.

I see.
So, how does one go about quickly/easily testing those kinds of functions?

A boolean memory tag and a tag change script seem okay to me.

You could also use sendRequest with a Gateway message handler that calls the shared scripts. Since you’re using a parameter, you could pass a payload within sendRequest to specify the datasink name.

In Gateway message handler: shared.StoreAndForward.cachePending(payload["name"])

In script console: system.util.sendRequest("projectName", "messageHandlerName", {"name":"myDataSinkName"})

1 Like