Hi there,
I'm currently running into an issue when trying to pull the results of a query in a script.
Full back story: What i'm trying to do is I have a dropdown component {options} with a named query bound to it.
I then have a change script on the dropdown component {Value} that will take the results selected Id in the dropdown and pull all the data for that project. which I want to display the results to a text field component so that I can edit the entries in the DB and then save them.
In this change script it calls another query that pulls all the fields for the selected Id
Currently I just want to print the results to the console but am running into this error:
13:41:07.965 [AWT-EventQueue-0] ERROR com.inductiveautomation.ignition.client.util.gui.ErrorUtil - Error running property change script on Dropdown.props.value: Traceback (most recent call last):
File "<function:valueChanged>", line 8, in valueChanged
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:407)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor.execute(NamedQueryExecutor.java:173)
at com.inductiveautomation.ignition.gateway.db.namedquery.GatewayNamedQueryManager.execute(GatewayNamedQueryManager.java:92)
at com.inductiveautomation.ignition.common.db.namedquery.SecuredNamedQueryManager.execute(SecuredNamedQueryManager.java:78)
at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:419)
at jdk.internal.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: java.lang.ClassCastException: Cannot coerce value '[1, Good_Unspecified, Thu Mar 21 13:41:07 PDT 2024 (1711053667781)]' into type: class java.lang.Byte
com.inductiveautomation.ignition.common.GenericTransferrableException: Traceback (most recent call last):
File "<function:valueChanged>", line 8, in valueChanged
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:407)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor.execute(NamedQueryExecutor.java:173)
at com.inductiveautomation.ignition.gateway.db.namedquery.GatewayNamedQueryManager.execute(GatewayNamedQueryManager.java:92)
at com.inductiveautomation.ignition.common.db.namedquery.SecuredNamedQueryManager.execute(SecuredNamedQueryManager.java:78)
at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:419)
at jdk.internal.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: java.lang.ClassCastException: Cannot coerce value '[1, Good_Unspecified, Thu Mar 21 13:41:07 PDT 2024 (1711053667781)]' into type: class java.lang.Byte
at org.python.core.Py.JavaError(Py.java:545)
at org.python.core.Py.JavaError(Py.java:536)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:553)
at org.python.core.PyObject.__call__(PyObject.java:477)
at org.python.core.PyObject.__call__(PyObject.java:481)
at org.python.pycode._pyx155.valueChanged$1(<function:valueChanged>:14)
at org.python.pycode._pyx155.call_function(<function:valueChanged>)
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyFunction.function___call__(PyFunction.java:474)
at org.python.core.PyFunction.__call__(PyFunction.java:469)
at org.python.core.PyFunction.__call__(PyFunction.java:464)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:868)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1010)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:950)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:161)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:98)
at com.inductiveautomation.perspective.gateway.model.PropertyChangeScript.access$001(PropertyChangeScript.java:31)
at com.inductiveautomation.perspective.gateway.model.PropertyChangeScript$ScriptSequencer.run(PropertyChangeScript.java:162)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.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 com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: com.inductiveautomation.ignition.common.GenericTransferrableException: java.lang.Exception: java.lang.Exception: java.lang.ClassCastException: Cannot coerce value '[1, Good_Unspecified, Thu Mar 21 13:41:07 PDT 2024 (1711053667781)]' into type: class java.lang.Byte
... 28 common frames omitted
Caused by: com.inductiveautomation.ignition.common.GenericTransferrableException: java.lang.ClassCastException: Cannot coerce value '[1, Good_Unspecified, Thu Mar 21 13:41:07 PDT 2024 (1711053667781)]' into type: class java.lang.Byte
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:407)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor.execute(NamedQueryExecutor.java:173)
at com.inductiveautomation.ignition.gateway.db.namedquery.GatewayNamedQueryManager.execute(GatewayNamedQueryManager.java:92)
at com.inductiveautomation.ignition.common.db.namedquery.SecuredNamedQueryManager.execute(SecuredNamedQueryManager.java:78)
at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:419)
at jdk.internal.reflect.GeneratedMethodAccessor148.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)
... 25 common frames omitted
Caused by: com.inductiveautomation.ignition.common.GenericTransferrableException: Cannot coerce value '[1, Good_Unspecified, Thu Mar 21 13:41:07 PDT 2024 (1711053667781)]' into type: class java.lang.Byte
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1627)
at com.inductiveautomation.ignition.common.TypeUtilities.coerceNullSafe(TypeUtilities.java:877)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.coerce(NamedQueryExecutor.java:419)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:384)
... 33 common frames omitted
Here is the change script:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
# Check if the dropdown value is not None and not the same as previous to avoid unnecessary queries
if currentValue != previousValue and currentValue is not None:
# Define parameters for your named query
params = {"selectedProjectId": currentValue}
# Run the named query to get project details
projectDetails = system.db.runNamedQuery("GetProjectDetails", params)
results = system.dataset(projectDetails)
# Print the query results
print(results)
When I test this query the results are returned as expected but when I use the dropdown component to try the functionality this is when I get the error.
Please let me know if anymore information is needed and thank you for any help offered.