Tag Change Event Not Triggering

I created a script to run a sql database query to insert data.
This script is supposed to run whenever a tag from the machine changes, basically the tag signals the process is finished, thus I try to capture some variables and send them to the database.

This script works if I put it under a button mouseclick event. but if I put it under a tag change event it does not work.

I’ve played with the tag change event, and unless I make my script super simple, it is not reliable.
By using my script however, it never runs, not even once have I been able to write to the data base.
My Script runs on value tag change from [Ignition-raspberrypi_edge]FILL_COMPLETE
Here is my script:

"complete = system.tag.getTagValue(’[Ignition-raspberrypi_edge]FILL_COMPLETE’)
system.gui.messageBox(‘hi 0’)
batch_id = system.tag.read(’[Ignition-raspberrypi_edge]BATCH_ID’)
cont_num = system.tag.read(’[Ignition-raspberrypi_edge]Total_Containers’)
weight = system.tag.read(’[Ignition-raspberrypi_edge]Weight’)
target = system.tag.read(’[Ignition-raspberrypi_edge]Target_Weight’)
deviation = target.value - weight.value
system.gui.messageBox(‘hi 1’)
date = system.date.now()

if complete == 1:
system.gui.messageBox(‘hi 2’)
system.db.runPrepUpdate(“INSERT into BATCH_INFO (Batch_ID,Container_num,Weight,Deviation,Date_Time) VALUES(?,?,?,?,?)”, [batch_id.value,cont_num.value,weight.value,deviation,date.value])"

A couple things. When posting code can your wrap it in ‘’’ before and after. This will keep your format so we can see if the format has any issue.

My second question is for your first line your doing system.tag.getTagValue() Why are you doing that when your using system.tag.read() everywhere else.

The next thing I would wonder about, you have 4 different system.gui.messageBox() lines in your code. When your running it from a button I would expect those to work but when your running it from a tag change event, I would assume you either have it in your gateway event scripts or as a tag event value change script. Both would run on the gateway instead of a client so I wouldn’t expect those lines to work.

The next would be in you prep update query your date is listed as date.value but your filling it in above using system.date.now(). Filling in your variable using that you shouldn’t need the .value after your date variable.

When your script should trigger are you getting any errors in your log? If the script runs and fails it should give an error. This should help point to the line in your code that caused it to fail. If it is a gateway tag change script, if you look at your tag change script does it show it has run yet?

1 Like

" if you look at your tag change script does it show it has run yet"
Could you please confirm what did you mean by that? how to check if if tag script was run - in the diagnostic execution or logs?