# Cannot coerce value into type: class java.lang.Byte

**URL:** <https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-lang-byte/87723>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 21, 2024, 9:00pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-lang-byte/87723 "2024-03-21T21:00:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jordan\_S](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Jordan\_S](https://forum.inductiveautomation.com/u/Jordan_S)\
**Post date:** [March 21, 2024, 9:00pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-lang-byte/87723/1 "2024-03-21T21:00:49Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 21, 2024, 9:09pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-lang-byte/87723/2 "2024-03-21T21:09:50Z")

</div>

The problem is here (with linebreaks for legibility):

```auto
Cannot coerce value '[1, 
                      Good_Unspecified, 
                      Thu Mar 21 13:41:07 PDT 2024 (1711053667781)
]' into type: class java.lang.Byte

```

`currentValue` is returning a "qualified value" with [value, quality, timestamp]. Your query is just expecting the value part of that.

Try,  
`params = {"selectedProjectId": currentValue.value}`

> **[Scripting Object Reference | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/scripting-object-reference#qualifiedvalue)**
>
> This page describes several common scripting objects

---

<div class="post-metadata">

**Author:** ![Jordan\_S](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Jordan\_S](https://forum.inductiveautomation.com/u/Jordan_S)\
**Post date:** [March 21, 2024, 9:32pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-lang-byte/87723/3 "2024-03-21T21:32:32Z")

</div>

You Are Amazing! Thank you!!!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 21, 2024, 9:34pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-lang-byte/87723/4 "2024-03-21T21:34:47Z")

</div>

Having a well written question with all the information required is a big help. Yours did and it was all properly formatted too!
