# Overwriting a dataset tag

**URL:** <https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025>\
**Category:** Ignition\
**Created:** [July 30, 2019, 11:20pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025 "2019-07-30T23:20:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jomo23](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jomo23](https://forum.inductiveautomation.com/u/jomo23)\
**Post date:** [July 30, 2019, 11:20pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025/1 "2019-07-30T23:20:48Z")

</div>

Hi Everyone,

I currently have a dataset tag that has two columns on it. The first column is named ColName1 and the second column I have is a Boolean. I would like to script this function on a button and once the button is pressed I would like to write the rows that have the Boolean checked as true onto a new dataset tag. I would like to be able to overwrite the dataset tag so that if I then unchecked the boolean on a row I would like to be able to overwrite the preexisting tag with the new values. Originally I tried to append the marked rows however I wasn’t able to remove any values that were previously marked. For example if I marked my values a b c d e as true I would like to write those values to my dataset tag. However, if I then marked b as false I would like the dataset tag to be written with only the a c d e values once the button is pressed.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 31, 2019, 12:18pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025/2 "2019-07-31T12:18:09Z")

</div>

The simplest way would be to iterate through the incoming dataset and pick the rows that are checked:

```python

dataIn = system.dataset.toPyDataSet(datasetIn)

headers = ['ColName1', 'Boolean']
dataOut = []

for row in dataIn:
  if row['Boolean'] == True:
    dataOut.append(list(row))

datasetOut = system.dataset.toDataSet(headers, dataOut)

```

EDIT: removed extraneous brackets around list(row). Sorry about that.

---

<div class="post-metadata">

**Author:** ![jomo23](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jomo23](https://forum.inductiveautomation.com/u/jomo23)\
**Post date:** [July 31, 2019, 3:38pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025/3 "2019-07-31T15:38:39Z")

</div>

Hi Jordan,

Will this code be able to overwrite what values are already on the tag since I see you are using the append function which I thought only adds onto what was previously on the dataset tag?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 31, 2019, 3:41pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025/4 "2019-07-31T15:41:45Z")

</div>

Hi Joe,

We make a brand new dataset every time. Notice that dataOut in line 4 is an empty list. We append to that list every time we see the boolean value as true. At the end, we create the new dataset to write to your second tag.

---

<div class="post-metadata">

**Author:** ![jomo23](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jomo23](https://forum.inductiveautomation.com/u/jomo23)\
**Post date:** [July 31, 2019, 4:04pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025/5 "2019-07-31T16:04:29Z")

</div>

I was able to replicate what you have however I am getting and error in the datasetOut = system.dataset.toDataSet(headers, dataOut) saying “IndexError: Row 0 doesn’t have the same number of columns as header list.”  
What might be the cause of this?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 31, 2019, 5:16pm UTC](https://forum.inductiveautomation.com/t/overwriting-a-dataset-tag/27025/6 "2019-07-31T17:16:45Z")

</div>

I edited my original post, because I accidentally had brackets around the list(row) portion of the script. Nothing will hose over your day like a typo. 🙂

Anyway, check to see if those brackets are in your script. If they are, remove them.

Instead of

```auto
dataOut.append([list(row)])

```

it should be

```auto
dataOut.append(list(row))

```
