# Global script help

**URL:** <https://forum.inductiveautomation.com/t/global-script-help/3759>\
**Category:** Ignition\
**Created:** [December 15, 2011, 5:26pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759 "2011-12-15T17:26:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [December 15, 2011, 5:26pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/1 "2011-12-15T17:26:03Z")

</div>

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])
	else:
		system.db.runPrepUpdate("UPDATE comphistory SET endalarmdate = CURRENT_TIMESTAMP WHERE compid = ? AND endalarmdate IS NULL", [deviceId])[/code]
```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 15, 2011, 5:35pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/2 "2011-12-15T17:35:37Z")

</div>

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

So you should be able to do:

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

to get the quality.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 15, 2011, 5:38pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/3 "2011-12-15T17:38:22Z")

</div>

You might also need to try doing it [this way.](http://inductiveautomation.com/forum/viewtopic.php?f=70&t=7386)

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [December 15, 2011, 6:09pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/4 "2011-12-15T18:09:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 15, 2011, 6:24pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/5 "2011-12-15T18:24:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [December 15, 2011, 8:03pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/6 "2011-12-15T20:03:04Z")

</div>

Ive tried and it wont print!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 16, 2011, 6:11pm UTC](https://forum.inductiveautomation.com/t/global-script-help/3759/7 "2011-12-16T18:11:35Z")

</div>

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

[Here’s a topic on printing to the gateway console](http://inductiveautomation.com/forum/viewtopic.php?f=70&t=7185&p=21414&hilit=print+console#p21414).
