which is the correct place for a declaration of the function in the Tag Event Scripts in Value Events-Value Changed before of the if currentValue.value: line (code1) or after the if currentValue.value: line (code2)
code1:
def funcion_hist(id_Variable):
objTS = system.tag.read("[.]../HeartBeatSystem/ts_MsSQL")
strConsultaSQL = system.db.runQuery("SELECT TOP(1) " + id_Variable + " FROM HrsOperadas
ORDER BY hrsoperadas_ndx DESC", database="cnxMsSQL")
for row in strConsultaSQL:
strHrs = row[0]
query = "INSERT INTO HistorialHrsOperadas (id_Variable, Valor, id_TimeStamp) VALUES (?, ?, ?)"
args = [id_Variable.value, strHrs.value, objTS.value]
system.db.runPrepUpdate(query, args, database="cnxMsSQL")
if currentValue.value:
funcion_hist("BbaSubFlujo_1")
funcion_hist("BbaSubFlujo_2")
funcion_hist("BbaSubFlujo_3")
funcion_hist("BbaSubFlujo_4")
or
code2:
if currentValue.value:
def funcion_hist(id_Variable):
objTS = system.tag.read("[.]../HeartBeatSystem/ts_MsSQL")
strConsultaSQL = system.db.runQuery("SELECT TOP(1) " + id_Variable + " FROM HrsOperadas
ORDER BY hrsoperadas_ndx DESC", database="cnxMsSQL")
for row in strConsultaSQL:
strHrs = row[0]
query = "INSERT INTO HistorialHrsOperadas (id_Variable, Valor, id_TimeStamp) VALUES (?, ?, ?)"
args = [id_Variable.value, strHrs.value, objTS.value]
system.db.runPrepUpdate(query, args, database="cnxMsSQL")
funcion_hist("BbaSubFlujo_1")
funcion_hist("BbaSubFlujo_2")
funcion_hist("BbaSubFlujo_3")
funcion_hist("BbaSubFlujo_4")
PD. sorry for the tab order but the original code have the correct tabs between lines.
Regards Gerardo