Modifying available gateway scripting functions after call to initializeScriptManager()

Is it possible to change the available gateway scripting functions on the fly after the module has come up and initializeScriptManager() has already been called? If so, how would one go about achieving this?

To make this more clear, I am working on a project with many scripting functions that we initialize and make available through the normal method of overriding initializeScriptManager() and then using manager.addScriptModule() to add the modules. This works great, but we are working on a new feature where we may only want to expose certain functions on the gateway based on other settings in the system that can be changed in the gateway web page at any time. I can easily set things up so that the right functions are conditionally added and made available based on the settings at the time initializeScriptManager() is called on module startup, but I can’t figure out how to change it later. I tried playing with the clearModule() and clearThirdPartyModule() methods of ScriptManager, but they had no discernible effect on which functions were available when I tested the intellisense within a gateway event script.

If it is simply set at initializeScriptManager() and cannot be changed dynamically later, we will probably have to document that a module restart is required for certain changes to take effect.

Another separate but related question which came up while playing with this and debugging… I noticed initializeScriptManager() being called on our gateway module 6 times with different script managers and I am curious what each of these may be or what the different types are. I understand that one is for the gateway context and is the same as what would be returned by GatewayContext.getScriptManager(), but I don’t know what the others are.

Thank you!

There’s one call for gateway scope (for tag events and tag expression runScript() calls) and one call for each project. The ‘project’ value is different for each project scope, so needs its own script manager. When a project is saved, that project’s script manager is re-initialized. When a shared script is edited and saved, all script managers are re-initialized. You might want to look for ways to programmatically trigger a shared script “save” when you need to reconfigure your exposed functions.

If you are feeling brave, you could delve into the locals map of the script manager after you initialize it to get to the dictionary of the system.whatever submodule that you populated with your functions. Could be tricky, though, and you’d be risking memory leaks if you held anything other than weak references.

Thank you for the information and ideas. Since there does not appear to be a straight forward mechanism for achieving this, and because there will be other complex interactions when our settings change, it looks like we will most likely force or require a module restart to take place when these changes are made.

Yeah, I can’t think of any good way to do this. The system knows to re-build the script managers when modules change and when project resources that it thinks affect the scripting system changes, but there’s not a hook for modules to prod the system into updating the scripting managers on demand.