Executing Python from Module

I’d like to execute a Gateway script from inside my module. Is the ScriptManager method runFunction() designed to do this? If not can I create code that imports an existing Python script and use runCode? Am not at all clear from Javadoc on how to accomplish this.

Thanks in advance for your help.
— chuck

The runCode() function would let you attempt to run some arbitrary Jython code; is that what you’re asking? Or are you trying to run some project’s existing gateway script?

I’d like to execute a Gateway script that is pre-existing — written outside the module.
— chuck

what sort of gateway script precisely are you talking about that you want to invoke?

These are user-written scripts sitting in my “Script Modules” node in the Designer nav tree. I believe these are what the documentation refers to as “Gateway Scripts”. I need to pass the data into the Python, but have no need for a response.

– chuck

Scripts written in the script modules area are reusable bits of code that can be used from both client and gateway scopes. If something in the manual is referring to these as “gateway scripts” then it’s incorrect.

You should be able to run one of these modules like this, assuming you’ve got yourself a ScriptManager instance.

scriptManager.runCode("app.WhateverModule.whateverUserCreatedFunctionYouWant()", scriptManager.createLocalsMap(), "some-arbitrary-filename");

thanx, I’ll give it a shot.
— chuck

scriptmgr.runCode("app.ils.callback.handleCompletion",mgr.createLocalsMap(),"xxx"); gives a JythonExecException: File “xxx” in line 1 in , name “app” is not defined"

It seems as if this call expects Python code in an external file, whereas my code is, in the designer, in Configuration->Script Modules in a package app.lis.callback. The callback package has a method defined “handleCompletion”.

— chuck

[quote=“chuckcoughlin”]scriptmgr.runCode("app.ils.callback.handleCompletion",mgr.createLocalsMap(),"xxx"); gives a JythonExecException: File “xxx” in line 1 in , name “app” is not defined"

It seems as if this call expects Python code in an external file, whereas my code is, in the designer, in Configuration->Script Modules in a package app.lis.callback. The callback package has a method defined “handleCompletion”.

— chuck[/quote]

Are ‘mgr’ and ‘scriptmgr’ the same instances of ScriptManager? What’s going on there? And why doesn’t handleCompletion have the open/close paranethesis?

The mgr/scriptmgr are the ScriptManagers gotten from the GatewayContext. My bad. Added (), same result.

I’m just concerned that you have two of them. That shouldn’t be the case…

Not at all, I was just trying to spruce up the code for public display, and messed up. Here it is unaltered:

mgr.runCode(scriptName,mgr.createLocalsMap(),null); where script name is “app.ils.callback.handleCompletion()” and I’ve tried various values for the file name (a file name argument doesn’t make sense to me(??)).

Don’t get thrown off by the filename thing. Python just wants something to put in tracebacks if there’s an error. It’s not used in any meaningful way.

Where are you getting a hold of this script manager?

ScriptManager mgr = context.getScriptManager(); 

where context is the gateway context.

– chuck

There’s your problem. You’re grabbing the gateway’s general script executor, but you’re trying to execute a global script that is part of a project. You need to grab that project’s script manager:

context.getProjectManager().getProjectScriptManager(projectId)

Thank you. That was the issue. Makes perfect sense. Is now working.

— chuck