# Updating numeric text field

**URL:** <https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878>\
**Category:** Ignition\
**Created:** [June 22, 2020, 4:39pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878 "2020-06-22T16:39:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![toddayers](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@toddayers](https://forum.inductiveautomation.com/u/toddayers)\
**Post date:** [June 22, 2020, 4:39pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/1 "2020-06-22T16:39:57Z")

</div>

I have about 10 different buttons that reflect a department for each one. I am wanting to be able to select a button and it fire a sql query to retrieve information from a table that have the rows that equate to that department. So if I select the safety department, my designated numeric text field updates with the average safety number of all the rows that have the safety area in the column. here is what I have so far:  
[//event.source.parent.getComponent](https://event.source.parent.getComponent)(‘Saverage’).intValue = system.db.runQuery("SELECT AVG(CAST(Safety AS int)) AS SafetyNumber FROM SQDCME.dbo.SQDCME where Area = ‘Stacker1’ ")//

The problem is that I get an error back saying:

File “event:actionPerformed”, line 23, in

AttributeError: ‘NoneType’ object has no attribute ‘intValue’

Basically I am trying to get the average safety number from the Safety column that has all the rows with the Stacker1 area in it.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2020, 4:46pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/2 "2020-06-22T16:46:31Z")

</div>

> [@toddayers](#):
>
> `event.source.parent.getComponent(‘Saverage’).intValue`

This lookup is failing - `getComponent('Saverage')` is returning None, Python's stand-in for `null`, which doesn't have an `intValue` property, and thus is throwing the error you're seeing. Double check the component name, whether it's inside any groups/containers, etc. Use the property selector panel on the right hand side of the script editor to confirm the path to the component you want.

---

<div class="post-metadata">

**Author:** ![toddayers](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@toddayers](https://forum.inductiveautomation.com/u/toddayers)\
**Post date:** [June 22, 2020, 4:54pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/3 "2020-06-22T16:54:40Z")

</div>

Yeah, so I went back and checked the scrip editor and it was in a container:

event.source.parent.getComponent(‘Container’).getComponent(‘Saverage’).intValue

and after I ran that I got:

File “event:actionPerformed”, line 23, in

TypeError: can’t convert Dataset [1R ? 1C] to int

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2020, 5:00pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/4 "2020-06-22T17:00:54Z")

</div>

> [@toddayers](#):
>
> system.db.runQuery("SELECT AVG(CAST(Safety AS int)) AS SafetyNumber FROM SQDCME.dbo.SQDCME where Area = ‘Stacker1’ ")

Okay, so now the problem is the other half of that line 🙂  
`system.db.runQuery` returns a dataset. If you know your query will only return one result, you can just switch your call from `runQuery` to [`runScalarQuery`](https://docs.inductiveautomation.com/display/DOC80/system.db.runScalarQuery) - it'll automatically pull out the first row/column of the result.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 22, 2020, 5:00pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/5 "2020-06-22T17:00:59Z")

</div>

Because the Query is returning a dataset which contains a column “SafetyNumber” and a row (the value). You can either directly assign a value form the dataset, or you can change the query to return a scalar value.  
I think you could do

```auto
event.source.parent.getComponent(‘Container’).getComponent(‘Saverage’).intValue = system.db.runQuery("SELECT AVG(CAST(Safety AS int)) AS SafetyNumber FROM SQDCME.dbo.SQDCME where Area = ‘Stacker1’ ").getValueAt(0,0)

```

---

<div class="post-metadata">

**Author:** ![toddayers](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@toddayers](https://forum.inductiveautomation.com/u/toddayers)\
**Post date:** [June 22, 2020, 5:12pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/6 "2020-06-22T17:12:31Z")

</div>

Well I am trying to get the safety number average of all the rows that have the Stacker1 value in the Area Column.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 22, 2020, 5:15pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/7 "2020-06-22T17:15:51Z")

</div>

We understand that, but the container you’re placing the value into only cares about the value - not the name. Switching to runScalarQuery will return just the simple value of the query, instead of the result set, which is structured as - in your case - a dataset with a named column and a value row.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2020, 5:16pm UTC](https://forum.inductiveautomation.com/t/updating-numeric-text-field/35878/8 "2020-06-22T17:16:15Z")

</div>

Right, but your _query_ is doing that aggregation (on the DB side). When it comes into Ignition, it will always be one value. But, the `runQuery` function returns a dataset _in all cases_ - whether you’re returning 100 rows x 5 columns or 1 row x 1 column.
