Global script help

What am I doing wrong here? I have this global script that gets called by a gateway tag change script. what I am trying to add is the tag quality to the script, to verify that I have good quality before inserting a record. I am seeing duplicate records when a device loses comms so I figure that if I look at the quality before doing the insert, I should be ok. Ive tried doing “Good” and also 192, but neither work.

[code]def alarmChange(deviceName, newValue):
import system, app

result = system.db.runPrepQuery("SELECT id FROM compdevices WHERE poll = 1 AND devicename = ?", [deviceName])

if len(result):
	deviceId = result[0][0]
	tagQuality = system.tag.getTagValue("%s/Comp_Stat.Quality" % (deviceName))
	if newValue == 1 and tagQuality == "Good":
		system.db.runPrepUpdate("INSERT INTO comphistory (compid, startalarmdate) VALUES (?, CURRENT_TIMESTAMP)", [deviceId])
		system.db.runPrepUpdate("UPDATE comphistory SET endalarmdate = CURRENT_TIMESTAMP WHERE compid = ? AND endalarmdate IS NULL", [deviceId])[/code]

Well, system.tag.getTagValue returns the tags value, which is a QualifiedValue (I think).

So you should be able to do:

tagQuality = system.tag.getTagValue("%s/Comp_Stat.Quality" % (deviceName)).quality

to get the quality.

You might also need to try doing it this way.

neither of those work. any other ideas? it doesnt make sense to me.

print the result of system.tag.getTagValue and see what you get, that might provide some insight.

Ive tried and it wont print!

It won’t put it where you can immediately see it.

Here’s a topic on printing to the gateway console.