How do I get the current project name from GatewayHook?
Can you tell us a little more about what you're trying to do? The gateway doesn't really have a "current project" -- that would be a concept more for the Designer or the Client scopes.
I have several functions that need to receive the name of the current project. Currently, I’ve set up the script module like this:
@Override
public void initializeScriptManager(ScriptManager manager) {
super.initializeScriptManager(manager);
manager.addScriptModule("system.myFunc",new CommonScript(context));
}
However, what I actually intend to do is pass the project name as well, like so:
manager.addScriptModule("system.myFunc",new CommonScript(context, projectName));
To achieve this, I attempted to use ModuleRPCFactory
inside the DesignerHook
:
@Override
public void startup(DesignerContext context, LicenseState activationState) throws Exception {
ModuleRPC rpc = ModuleRPCFactory.create(ModuleMeta.MODULE_ID, ModuleRPC.class);
System.out.println("getProjectName:"+rpc.getProjectName(context.getProjectName()));
}
Unfortunately, I wasn’t able to retrieve the project name on the GatewayHook
side.
What is the correct way to get the current project name and pass it to the relevant functions?
Don't do that. Use ScriptContext within your implementation of each call.
Use ScriptContext
(n.b. the API is completely different in 8.3) and consider also accepting a trailing project name parameter in your scripting function implementations, so that your end users can override it or provide one if ScriptContext
isn't working; for instance, there's an unfixable bug in all versions prior to 8.3 where 'stacking' script executions (e.g. a tag change script running a report that itself runs a script during data gathering) would fail in 'weird' ways.
Thank you, it's done.