# More Value Changed Event Blues

**URL:** <https://forum.inductiveautomation.com/t/more-value-changed-event-blues/33964>\
**Category:** Ignition\
**Created:** [April 15, 2020, 8:14pm UTC](https://forum.inductiveautomation.com/t/more-value-changed-event-blues/33964 "2020-04-15T20:14:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [April 15, 2020, 8:14pm UTC](https://forum.inductiveautomation.com/t/more-value-changed-event-blues/33964/1 "2020-04-15T20:14:19Z")

</div>

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:

```auto
	#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’

```auto
UPDATE igeventdef SET IG_Event_Index = :IG_Index WHERE IG_PLC_Tag = :IG_Tag;

```

‘Get\_Alarm’

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 15, 2020, 8:21pm UTC](https://forum.inductiveautomation.com/t/more-value-changed-event-blues/33964/2 "2020-04-15T20:21:46Z")

</div>

[system.db.runNamedQuery()](https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery) needs a project name in gateway scope. Even if called from within the same gateway project scope. /:

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 15, 2020, 8:22pm UTC](https://forum.inductiveautomation.com/t/more-value-changed-event-blues/33964/3 "2020-04-15T20:22:28Z")

</div>

You should have had errors in your gateway logs that gave a hint…

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [April 16, 2020, 11:42am UTC](https://forum.inductiveautomation.com/t/more-value-changed-event-blues/33964/4 "2020-04-16T11:42:19Z")

</div>

Again, excellent!!!  
Thank You
