# Error trying to coerce value with system.dataset.setValue

**URL:** <https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [March 4, 2022, 10:14pm UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868 "2022-03-04T22:14:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EMarsupial](https://avatars.discourse-cdn.com/v4/letter/e/f07891/32.png) [@EMarsupial](https://forum.inductiveautomation.com/u/EMarsupial)\
**Post date:** [March 4, 2022, 10:14pm UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868/1 "2022-03-04T22:14:51Z")

</div>

The script I am testing is taking an data from a table and replacing the integer 1 with ‘Enabled’ or 0 with ‘Disabled’.  
I get the following error:

Traceback (most recent call last):  
File “event:actionPerformed”, line 7, in   
ValueError: Error trying to coerce ‘Enabled’ to a number.

script:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/c/fc729ca96a093b051b4b54045aa7adc2e9317701.png)

```auto
table = event.source.parent.getComponent('Table')
data = table.data

for row in range(data.getRowCount()):
	n2Status = data.getValueAt(row, 'nitro_enable')
	if n2Status == 1:
		newData = system.dataset.setValue(data, row, ('nitro_enable'), str('Enabled'))
	
		

```

---

<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 4, 2022, 10:47pm UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868/2 "2022-03-04T22:47:12Z")

</div>

Tip: post code (and format it using the `</>` code formatting button) rather than a pictures of code. That way we can copy and paste it into our answers.

---

<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 4, 2022, 10:59pm UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868/3 "2022-03-04T22:59:30Z")

</div>

Check if you’re trying to force a string into a numeric field. Try adding in a print statement with `type(row['nitro_enable'])`.  
If it comes back with a numeric type then that’s your problem.

Other things:

- You don’t need parentheses in `... data, row, ('nitro_enable') ...`.
- You don’t need to convert ‘Enabled’ to a string. It already is one.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 5, 2022, 3:14am UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868/4 "2022-03-05T03:14:36Z")

</div>

As @Transistor hinted at, the type of column nitro\_enable is numeric. So if you want to convert it you will need to either rebuild the dataset with the `system.dataset.*` functions, or the DatasetBuilder class.

For reference see:

> [@Vision: Convert dataset column type](https://forum.inductiveautomation.com/t/vision-convert-dataset-column-type/26341/2):
>
> Use Ignition’s [DatasetBuilder](http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/com/inductiveautomation/ignition/common/util/DatasetBuilder.html). Something like this: from com.inductiveautomation.ignition.common.util import DatasetBuilder from java.lang import Integer, String, Object from java.awt import Color def forceTypes(sqlDS): builder = DatasetBuilder.newBuilder() builder.colNames(sqlDS.columnNames) originalTypes = list(sqlDS.columnTypes) i = #some column index for a color originalTypes[i] = Color builder.colTypes(originalTypes) for r in range(sqlDS.rowCount): bui…

---

<div class="post-metadata">

**Author:** ![EMarsupial](https://avatars.discourse-cdn.com/v4/letter/e/f07891/32.png) [@EMarsupial](https://forum.inductiveautomation.com/u/EMarsupial)\
**Post date:** [March 8, 2022, 6:04pm UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868/5 "2022-03-08T18:04:08Z")

</div>

Almost positive that’s the problem. It is either a 1 or 0, I want to replace the number with the string.

---

<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 8, 2022, 8:43pm UTC](https://forum.inductiveautomation.com/t/error-trying-to-coerce-value-with-system-dataset-setvalue/56868/6 "2022-03-08T20:43:36Z")

</div>

> [@EMarsupial](#):
>
> Almost positive that’s the problem.

Did you try the `type()` function as I suggested?  
Is the database column a text column (what you want) or a boolean / integer column (which is not what you want)?

Paste your updated code (and not a screengrab) and the result.
