I have a table with 2 columns [city, number], every time a new city and number is entered, I want to check it against the previous row's city and numbers. If the new row's values is different than the previous, I want to open a popup. For example if first row is [NYC, 101] and the next is [Dallas, 43] the popup will open. If the next row is [Dallas, 43] nothing happens, if the 4th is [Houston, 22] the popup opens.
This is what I have right now but i'm not sure how to compare new row to previous row
cityNum = system.db.runNamedQuery('getTable') #just an example, returns 2 columns city and num
i = 0
if cityNum.getRowCount() >= 0:
while i < cityNum.getRowCount():
#I was thinking maybe something like this.. if cityNum.getValueAt(i, 'City', 'Num')
In this case we loop through the dataset checking the if the previous value is equal to the current value. Dataset have a bit of a learning curve at first, but the user manual is pretty helpful: Datasets - Ignition User Manual 8.0 - Ignition Documentation.
# Create sample data
headers = ['city', 'number']
rows = [
['NYC', 101],
['Dallas', 43],
['Dallas', 43],
['Houston', 22]
]
cityNum = system.dataset.toDataSet(headers, rows)
prevCity = None
prevNumber = None
# Iterate over dataset
for row in range(cityNum.getRowCount()):
# Get city and number for current row
city = cityNum.getValueAt(row, 'city')
number = cityNum.getValueAt(row, 'number')
# Check if city and number are different from last row
if not (prevCity == city) and not (prevNumber == number):
#Open Popup Here
print city, number
# Update previouse city and number
prevCity = city
prevNumber = number
So you just want to filter and see if the filtered ds is empty xd
here is some standerd filter function
def filterDataset(ds, **kwargs):
pds = system.dataset.toPyDataSet(ds)
output = []
for row in pds:
if all(row[key] == value for key, value in kwargs.items()):
output.append(row)
return system.dataset.toDataSet(list(ds.columnNames), output)
Consider starting the data entry process with a pop-up (I'm more of a pane guy myself). Supply the data entry interface with the last row of data and do whatever logic you have in mind.
NOTE: This code was entered from my phone it will not work due to the wrong type of single quotes. It is also untested and presented here as only an example.