# Writing a value to a perspective table from a script

**URL:** <https://forum.inductiveautomation.com/t/writing-a-value-to-a-perspective-table-from-a-script/75661>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [June 28, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-to-a-perspective-table-from-a-script/75661 "2023-06-28T17:00:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Thompson](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robert\_Thompson](https://forum.inductiveautomation.com/u/Robert_Thompson)\
**Post date:** [June 28, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-to-a-perspective-table-from-a-script/75661/1 "2023-06-28T17:00:26Z")

</div>

Greetings, this is probably an elementary question I should be able to answer, but how do I write a value to a perspective table using a script. For example, I want to zero out, or blank the values in a table when a button is pressed, so using a mouse click script what is the syntax for the write of values back to the table? I can read them no problem.  
Thanks for any input.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [June 28, 2023, 5:07pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-to-a-perspective-table-from-a-script/75661/2 "2023-06-28T17:07:21Z")

</div>

This will blank out your table but I suspect there may be more to what you want to accomplish?

```auto
self.getSibling("Table").props.data = None

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 28, 2023, 5:51pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-to-a-perspective-table-from-a-script/75661/3 "2023-06-28T17:51:39Z")

</div>

Use an `onActionPerformed` event on the button, not a click event.  
Add a script there.

If your table's `data` property is a dataset, use dataset methods/functions:  
[https://docs.inductiveautomation.com/display/DOC81/system.dataset](https://docs.inductiveautomation.com/display/DOC81/system.dataset)  
[https://docs.inductiveautomation.com/display/DOC81/Datasets#Datasets-AccessingDatainaDataset](https://docs.inductiveautomation.com/display/DOC81/Datasets#Datasets-AccessingDatainaDataset)

For example, several ways of zeroing a column 'foo':

```python
ds = path.to.table.props.data
# there might be a better way of doing this but I'm not sure
# what exactly is the type of the list returned there
headers = [col for col in ds.columnNames if col != 'foo']
type_of_foo = ds.getColumnType(ds.getColumnIndex('foo'))
foo = [0 for _ in xrange(ds.rowCount)]
ds = system.dataset.filterColumns(ds, headers)
ds = system.dataset.addColumn(ds, foo, 'foo', type_of_foo)
path.to.table.props.data = ds

```

```python
ds = path.to.table.props.data
for row in xrange(ds.rowCount):
    ds = system.dataset.setValue(ds, row, 'foo', 0)
path.to.table.props.data = ds

```

_disclaimer: I'm writing this code off the top of my head, and I'm not testing any of it._

If it's an array of objects, you can modify it in the same way you'd use a list of dicts.

---

<div class="post-metadata">

**Author:** ![Robert\_Thompson](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robert\_Thompson](https://forum.inductiveautomation.com/u/Robert_Thompson)\
**Post date:** [June 29, 2023, 12:04pm UTC](https://forum.inductiveautomation.com/t/writing-a-value-to-a-perspective-table-from-a-script/75661/4 "2023-06-29T12:04:46Z")

</div>

Thank you, I didn't realize the table was a data set. I had a couple of people tell me that, it makes more sense now. Thank you for the help.
