Overwriting a dataset tag

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.

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


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.

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?

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.

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?

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. :slight_smile:

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

Instead of

dataOut.append([list(row)])

it should be

dataOut.append(list(row))
1 Like