Removing ScriptModules from ScriptManager

Hello, I'm currently developing a third-party Java module that adds additional functions. I'm doing this the exact same way the IA scripting-function example is doing it, by having a ScriptModule, and adding it to the GatewayHook's ScriptManager by calling:
manager.addScriptModule("system.example", scriptModule, new PropertiesFileDocProvider());

Full GatewayHook.java in referenced project linked here: ignition-sdk-examples/scripting-function/scripting-function-gateway/src/main/java/com/inductiveautomation/ignition/examples/scripting/GatewayHook.java at b2f09134a86ec17320229e1ceffb0c5fecfc7643 · inductiveautomation/ignition-sdk-examples · GitHub

I'm trying to use a LicenseStateUpdateListener, to listen for a license state update, and to then remove the ScriptModule from the ScriptManager, if the license state is not activated. This is where I'm having trouble. I'm reading the ScriptManager 8.1.42 javadocs and trying things out.

I've tried both clearModule() and clearProjectScriptModules(), which both didn't appear to do anything. I've confirmed that a license state update came through as 'Trial', and they were invoked, but I was still able to access and invoke the module scripting functions from a designer.

Does anyone have any pointers to achieve this? Or do I need to be approaching this entirely differently.

Don't try to remove script modules. This isn't possible, first of all, and will only lead to confusion from your end users, rather than acceptance of licensing terms.

Instead, take note of the license state update and in your function implementations, do something different (throw an error, return an empty list, log a warning, etc) when your module isn't licensed.

1 Like

Gotcha, so following IA's scripting-function example, in GatewayScriptModule.java, how would you recommend having the class have access to license state updates? Or rather, having the class have access to the module's current license state?

Your options are myriad, but one possibility:
When constructing your GatewayScriptModule in your gateway hook, pass it a reference back to the GatewayHook of your module itself, and capture the current license state there as a field.
Or you could literally make your GatewayScriptModule a LicenseStartUpdateListener.
Or you could store GatewayContext in the GatewayScriptModule and use that to go back to the gateway to check license state in your scripting functions.

1 Like

Got it, will consider these options and potentially others. Thanks as always Paul.