Submit Button Scripting

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.

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.

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

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

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:

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)