My goal is to copy a row from one database table to another table.
The script works fine from the Script Console.
The Value Changed script is working as I can see the value of ‘Event_Index_Counter’ change each time I toggle the memory tag value from Off to On & On to Off.
I have tried adding the database name to each query, as is shown in the docs for system.db.runPrepUpdate with no change.
Any takers?
My Value Changed script:
#Set the event code, this changes with each event
event_code = "SCADA_ALARM_CP01_0_2"
#Read the IG_Event_Index value, this is a double int to keep track of each event
Idx_list = system.tag.readBlocking(["[default]Event_Index_Counter"])
Idx = Idx_list[0].value
#print Idx
#Increment IG_Event_Index to use in this transaction
Idx = Idx + 1
#print Idx
#Store the new IG_Event_Index value
system.tag.writeBlocking(["[default]Event_Index_Counter"],[Idx])
#Set Up the parameter values that are passed to the Named Queries
param1 = {"IG_Tag":event_code, "IG_Index":Idx}
param2 = {"IG_Tag":event_code}
#print param2
#Set the tansactions to be serialized
#TxId = system.db.beginTransaction("",8)
#Call the querys
system.db.runNamedQuery("Index",param1)
system.db.runNamedQuery("Get_Alarm", param2)
#Commit and close the transaction
#system.db.commitTransaction(TxId)
#system.db.closeTransaction(TxTd)
The two named query are:
‘Index’
UPDATE igeventdef SET IG_Event_Index = :IG_Index WHERE IG_PLC_Tag = :IG_Tag;
‘Get_Alarm’
INSERT INTO igeventdisp
(IG_Event_Index,
IG_PLC_Tag,
IG_Event_ID,
IG_Event_Icon,
IG_Event_Description,
IG_Event_Area,
IG_Event_Device,
IG_Event_Type,
IG_Event_Module,
IG_Event_Controller,
IG_Event_Group,
IG_Event_Category,
IG_Event_State,
IG_Event_Priority,
IG_Event_Cleared)
SELECT IG_Event_Index,
IG_PLC_Tag,
IG_Event_ID ,
IG_Event_Icon,
IG_Event_Description,
IG_Event_Area,
IG_Event_Device,
IG_Event_Type,
IG_Event_Module,
IG_Event_Controller,
IG_Event_Group,
IG_Event_Category,
IG_Event_State,
IG_Event_Priority,
IG_Event_Cleared
FROM igeventdef WHERE IG_PLC_Tag = :IG_Tag
ORDER BY IG_Event_Set_Time ASC;