# Submit Button Scripting

**URL:** <https://forum.inductiveautomation.com/t/submit-button-scripting/44217>\
**Category:** Ignition\
**Created:** [March 8, 2021, 12:44pm UTC](https://forum.inductiveautomation.com/t/submit-button-scripting/44217 "2021-03-08T12:44:40Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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 8, 2021, 1:29pm UTC](https://forum.inductiveautomation.com/t/submit-button-scripting/44217/6 "2021-03-08T13:29:41Z")

</div>

A few things:

1. You have chosen to cast things to a list which are already a list. Not a big deal really, but doesn't help in performance.
2. I believe you have misunderstood what getColumnAsList() does.
3. I would suggest moving away from getColumnAsList() as it isn't always available.

> [@getColumnAsList() in 7.9.14](http://forum.inductiveautomation.com/t/getcolumnaslist-in-7-9-14/37063/2):
>
> getColumnAsList is not a member of the Dataset interface. You must have been operating on an implementation of Dataset that had it, but now you’re not. If you print out the type of Dataset in the old version and current version you might see the difference. For example, a PyDataSet does not have getColumnAsList on it. (do something like print type(ds))

In this code `columnList = list(data.getColumnNames())` getColumnNames() already returns a list so there is no need to cast it to a list. `columnList = data.getColumnNames()` is better.

Same thing in `values += [t_stamp] + list(row)`, however in this case you would be better off using the append and extend functions of the list.

```auto
values = []
for row in pyData:
    values.append([t_stamp].extend(row))

```

Of course you can also achieve the same thing with a list comprehension

```auto
values = [[t_stamp].extend(row) for row in pyData]

```

Finally, `getColumnAsList(0)` returns the row values of column 0 as a list. So, when you loop through it, you are purposefully adding the value of the first column to your new row.

If your intention is to clear the dataset then the best method would be to call clearDataset. So, your new code can be simplified to the following:

```auto
data = event.source.parent.getComponent('PassFailTable').data
columnList = data.getColumnNames()
pyData = system.dataset.toPyDataSet(data)
t_stamp = system.date.now()

#Create column string for the query
columnString = '(t_stamp,' + ','.join(columnList) + ')'

#Create question marks for the prepQuery insert, adding one to each set of values for the timestamp
questionMarkString = ','.join(['('+','.join('?' * (len(columnList)+1)) + ')'] * len(pyData))

query = 'INSERT INTO Qualitydbo.Defecting_WasteBeltAudits %s VALUES %s' % (columnString,questionMarkString)

print query
#make a flat list out of the pyData
values = [[t_stamp].extend(row) for row in pyData]

system.db.runPrepUpdate(query,values)

tags = ['[Client]Defecting/Shift_1','[Client]Defecting/Shift_2']
Shift1values = [0,0]
system.tag.writeAll(tags,Shift1values)

#Clear the PassFailTable dataset
event.source.parent.getComponent('PassFailTable').data = system.dataset.clearDataset(data)

window = sysetm.nav.openWindow('Departments')
system.nav.centerWindow(window)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/submit-button-scripting/44217)._
