Jython Logic Not Working?

I’m inserting rows into a db table with a button, but first I run a NamedQuery that returns a list of current values in the db table. If the new insert matches one currently in the db, instead of inserting new rows, it updates the current row’s qty.
So the shortened code I’m using is this:

query = system.db.runNamedQuery('DuplicateChecker', vars)

duplicates = system.dataset.toPyDataSet(query)

style = row['STYLE'] + ' ' + size + material

if style not in duplicates:
       print 'Style is not currently in the database'

I put in some debugging code and verified that the duplicates datset is equal to
[0021910KP 5x5RB, 0F94-22KP 5x5RB]
and the style to check by is equal to
0021910KP 5x5RB
this obviously is in the dataset, so why does it print
Style is not currently in the database

Off hand I’d say it’s a type issue. duplicates should end up being a list.

query = system.db.runNamedQuery('DuplicateChecker', vars)

duplicates = system.dataset.toPyDataSet(query)

dupeList=duplicates.underlyingDataset.getColumnAsList(0)

style = row['STYLE'] + ' ' + size + material

if style not in dupeList:
       print 'Style is not currently in the database'

The zero in getColumnAsList is just the index number of the column. You should also be able to use column names.

2 Likes