Problem with parent project and SDK module

Hi, I have a project named test, which inherits some scripts and sfc from another project called global, so to make this work configure in Gateway Stettings in the Gateway Scripting Project part with the name "global", working correctly, however, I also have installed a SDK module that contains some additional scripts and with this configuration I can no longer call the methods inside the module, but if in Gateway Scripting Project I leave it empty "" it calls the module working correctly but I lose the sfc sequences, what could I do to make both work at the same time?

Explain. SDK modules generally do not contain or supply scripts. They supply scripting functions, exposed to all projects, but implemented in java. What exactly are you doing in this SDK module?

the module is performing a query in the database and is organizing the information to show what I want to see.

I meant, what exactly are you doing with scripts and/or script functions in this module? Show the related code, sanitized if necessary.

the sdk module contains this function script

system.yieldCalcMillA.data("scales_simulator", 0, system.date.getDate(2023, 0, 25), system.date.getDate(2023, 0, 23), 1)

and when running this in the console script as follows it comes out correctly

while when configuring it with the global name, the following is displayed

Java Traceback:
Traceback (most recent call last):
File "<input>", line 1, in <module>
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:351)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:325)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:278)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.moduleInvokeSafe(GatewayInterface.java:917)

at com.inductiveautomation.ignition.client.gateway_interface.ModuleRPCFactory$DynamicRPCHandler.invoke(ModuleRPCFactory.java:53)

at com.sun.proxy.$Proxy58.data(Unknown Source)

at com.inductiveautomation.ignition.examples.scripting.client.ClientScriptModule.dataImpl(ClientScriptModule.java:24)

at com.inductiveautomation.ignition.examples.scripting.AbstractScriptModule.data(AbstractScriptModule.java:22)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: class com.inductiveautomation.ignition.common.script.ProjectScriptModule cannot be cast to class com.inductiveautomation.ignition.common.Dataset (com.inductiveautomation.ignition.common.script.ProjectScriptModule and com.inductiveautomation.ignition.common.Dataset are in unnamed module of loader 'app')


at org.python.core.Py.JavaError(Py.java:547)

at org.python.core.Py.JavaError(Py.java:538)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:549)

at org.python.core.PyObject.__call__(PyObject.java:433)

at org.python.core.PyObject.__call__(PyObject.java:437)

at org.python.pycode._pyx11.f$0(<input>:1)

at org.python.pycode._pyx11.call_function(<input>)

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1687)

at org.python.core.Py.exec(Py.java:1731)

at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:611)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:599)

at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: class com.inductiveautomation.ignition.common.script.ProjectScriptModule cannot be cast to class com.inductiveautomation.ignition.common.Dataset (com.inductiveautomation.ignition.common.script.ProjectScriptModule and com.inductiveautomation.ignition.common.Dataset are in unnamed module of loader 'app')

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:351)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:325)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:278)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.moduleInvokeSafe(GatewayInterface.java:917)

at com.inductiveautomation.ignition.client.gateway_interface.ModuleRPCFactory$DynamicRPCHandler.invoke(ModuleRPCFactory.java:53)

at com.sun.proxy.$Proxy58.data(Unknown Source)

at com.inductiveautomation.ignition.examples.scripting.client.ClientScriptModule.dataImpl(ClientScriptModule.java:24)

at com.inductiveautomation.ignition.examples.scripting.AbstractScriptModule.data(AbstractScriptModule.java:22)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

... 19 more

Caused by: java.lang.ClassCastException: class com.inductiveautomation.ignition.common.script.ProjectScriptModule cannot be cast to class com.inductiveautomation.ignition.common.Dataset (com.inductiveautomation.ignition.common.script.ProjectScriptModule and com.inductiveautomation.ignition.common.Dataset are in unnamed module of loader 'app')

at com.inductiveautomation.ignition.examples.scripting.GatewayScriptModule.dataImpl(GatewayScriptModule.java:71)

at com.inductiveautomation.ignition.examples.scripting.AbstractScriptModule.data(AbstractScriptModule.java:22)

at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(null)

at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(null)

at java.lang.reflect.Method.invoke(null)

at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.ModuleInvoke.invoke(ModuleInvoke.java:167)

at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:431)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)

at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1450)

at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)

at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1631)

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)

at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)

at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)

at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at com.inductiveautomation.catapult.handlers.RemoteHostNameLookupHandler.handle(RemoteHostNameLookupHandler.java:121)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:322)

at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:59)

at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at org.eclipse.jetty.server.Server.handle(Server.java:516)

at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487)

at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)

at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)

at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)

at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)

at java.lang.Thread.run(null)

Traceback (most recent call last):
File "<input>", line 1, in <module>
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:351)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:325)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:278)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.moduleInvokeSafe(GatewayInterface.java:917)

at com.inductiveautomation.ignition.client.gateway_interface.ModuleRPCFactory$DynamicRPCHandler.invoke(ModuleRPCFactory.java:53)

at com.sun.proxy.$Proxy58.data(Unknown Source)

at com.inductiveautomation.ignition.examples.scripting.client.ClientScriptModule.dataImpl(ClientScriptModule.java:24)

at com.inductiveautomation.ignition.examples.scripting.AbstractScriptModule.data(AbstractScriptModule.java:22)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: class com.inductiveautomation.ignition.common.script.ProjectScriptModule cannot be cast to class com.inductiveautomation.ignition.common.Dataset (com.inductiveautomation.ignition.common.script.ProjectScriptModule and com.inductiveautomation.ignition.common.Dataset are in unnamed module of loader 'app')

You are going to have to work with the creator of this SDK module to resolve this. Whoever it is didn't bother to create their own package hierarchy after copying the scripting examples, so there's no indication where to look.

the module was developed by ourselves from the example for creating sdk modules from ignition example scripting function

  • Change the example package and module ID to your own hierarchy.

  • Show your SDK code for that function.

If you cannot share the code, you will probably need to arrange for commercial assistance under an NDA.

1 Like

could you show me an example of what you mention? because we change the id of the module

But you didn't change your package hierarchy. So your backtrace is full of com.inductiveautomation.ignition.examples. Your module ID and your package hierarchy should both start with your company's domain name, reversed.

4 Likes

I was testing by changing all that, however, it still has the same problem, the sdk module works perfectly when it is empty without any project, but as soon as I link one it stops working

So, you've followed the first of my recommendations. It is intended to make the second recommendation most useful, by uniquely correlating further backtraces against the code you share. I can't tell what's wrong with your code without seeing it.

I understand, the code has several components, some pom, some hooks, among others, I think the problem may be related to the scope of execution of the module, what part of the code should I share to visualize this?

Start by sharing:

  • Your gateway hook class

  • Your class submitted to .addScriptModule() that exposes system.yieldCalcMillA.data

  • Any class that has any use of ScriptManager.runCode() or .runFunction() (because you almost certainly should not be using those)

Gateway Hook

package com.dautom.yieldcalc.mill.a;

import com.inductiveautomation.ignition.common.licensing.LicenseState;
import com.inductiveautomation.ignition.common.script.ScriptManager;
import com.inductiveautomation.ignition.common.script.hints.PropertiesFileDocProvider;
import com.inductiveautomation.ignition.gateway.clientcomm.ClientReqSession;
import com.inductiveautomation.ignition.gateway.model.AbstractGatewayModuleHook;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GatewayHook extends AbstractGatewayModuleHook {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final GatewayScriptModule scriptModule = new GatewayScriptModule();

    private static GatewayContext gatewayContext;

    @Override
    public void setup(GatewayContext gatewayContext) {
        logger.info("setup()");
        GatewayHook.gatewayContext = gatewayContext;
    }

    @Override
    public void startup(LicenseState licenseState) {
        logger.info("startup()");
    }

    @Override
    public void shutdown() {
        logger.info("shutdown()");
    }

    @Override
    public void initializeScriptManager(ScriptManager manager) {
        super.initializeScriptManager(manager);

        manager.addScriptModule(
                "system.yieldCalcMillA",
                scriptModule,
                new PropertiesFileDocProvider());
    }

    @Override
    public Object getRPCHandler(ClientReqSession session, String projectName) {
        return scriptModule;
    }

    public static GatewayContext getGatewayContext() {
        return gatewayContext;
    }
}

Ok. Singleton script module pattern with RPC. (Does not support identifying calling clients--this pattern throws that information away.)

OK, so how can I make it work?

Make what work? We haven't yet determined what you've done that makes your code sensitive to the global scripting project setting. You have more to share.

it would be easier for me if you could provide me with an address or a way to share the complete code privately.

I don't do private for free, sorry.

1 Like