This is my script I have on value change event scripting on one tag. When this tag changes I want to query SQL for a result and write that to a memory tag. I'm not great at python so please have mercy.
Val1 = "[default]AGM_Assembly/L_06_PTester/Serial_Modified"
Val2 = "[default]AGM_Assembly/L_06_PTester/Serial_SkuLine"
params = {"SerialNum" : Val1 , "LineCode" : Val2}
SQLRead = system.db.runNamedQuery("Fully_Integrated_Overview","ASSY/p_Test_Lookup", params)
system.tag.writeAsync("[default]AGM_Assembly/L_06_PTester/SQL_Value", SQLRead)
This is the error I am getting. Any help?
java.lang.ClassCastException: Error trying to coerce '[default]AGM_Assembly/L_06_PTester/Serial_Modified' to a number.
You need to use system.tag.readBlocking
to read tag values. What you've written is trying to pass the literal string "XXX/Serial_Modified" as an integer value, rather than the value of a tag by that name.
The most direct replacement for what you're trying to do would be:
tagpaths = ["[default]AGM_Assembly/L_06_PTester/Serial_Modified", "[default]AGM_Assembly/L_06_PTester/Serial_SkuLine"]
qualifiedValues = system.tag.readBlocking(tagpaths)
Val1, Val2 = [qv.value for qv in qualifiedValues]
params = {"SerialNum" : Val1 , "LineCode" : Val2}
SQLRead = system.db.runNamedQuery("Fully_Integrated_Overview","ASSY/p_Test_Lookup", params)
system.tag.writeAsync("[default]AGM_Assembly/L_06_PTester/SQL_Value", SQLRead)
1 Like
Thank you! I knew I was missing something simple!