I have a script that is supposed to take a work order number and check whether it already exists in an SQL table. If it doesn't, it performs an insert query. Otherwise, it sets some tags that create a pop up warning on a vision screen. To do this, I have an if else statement that evaluates the row count after the initial SQL select query.
The issue I'm having is that the script performs both if and else statements. But what's odd is that it only performs the tag writing for the warning, it does not perform the print statement and it does not set retVal = -2. I've triple checked and that's the only instance where the warning ID tag is set to 1.
A vision client tag runs this script and initializes some stuff that happens in a timer script.
Gotcha, thanks for the tip. I figured since I have a few other functions buried in this code, it wouldn't help to be able to copy and paste it. For reference here it is:
def EnterWOinDB():
# Get the work order number, database information, and columns
wo_num = system.tag.readBlocking("[default]Form104/WO_Entry/WONum_Form104")[0].value
database, wo_table, recipe_table = project.WOEntry.GetRecipe_Functions.GetDBInfo(104)
wo_params = project.WOEntry.GetRecipe_Functions.GetWOParams()
# Values to insert into table (WO number, no part number, machine number 104)
wo_vals = [wo_num, 'NA', 104]
# Check to see if WO exists
retVal, dataset = project.db.dml.selectData(['*'],['WONum'], [wo_num], wo_table, database)
pyDataSet = system.dataset.toPyDataSet(dataset)
print pyDataSet.getRowCount()
# WO already exists
if pyDataSet.getRowCount() > 0:
# Set warning popup
print "Workorder already exists"
system.tag.writeBlocking("[default]Form104/WO_Entry/Warnings/WarningID", 1)
system.tag.writeBlocking("[default]Form104/WO_Entry/Warnings/WarningActive", 1)
retVal = -2
# Insert WO into table
else:
print "WorkOrder does not already exist"
retval = project.db.dml.insertRow(wo_params, wo_vals, wo_table, database)
return retVal
Gotta run through the basics, since we're looking at this from fresh eyes:
If you update the script to write a crazy value, does it write the crazy value, or still 1?
It looks like no, because of what you pasted here, but just to double check - any mixed indentation in the actual script file? Right click and in the appearance options you can 'show whitespace' - four spaces look visually identical to a tab but can behave differently in Jython which can throw things off.
Can you use the tag reference tracker to see anything else that might be interacting with that tag?
Separately, is a global tag the right choice for (ultimately) indirectly warning a particular operator of something? I'd consider migrating to a Vision client tag (which would also sidestep the entire possibility of some external thing writing to the tag and causing this confusion).
Why use a tag at all if they're only passing it off to a database to be inserted? Instructions say to scan a work order and press enter, but I would think scanning and clicking a button would be easier (or just let them use the enter key to trigger the script). Either way unless the tag is used for something else, I'd skip using the tag completely. Plus avoids multiple users from using the form at the same time with conflicting work orders. (But maybe there's only 1 user ever at a time)