# Problems getting quality code for bad tags

**URL:** <https://forum.inductiveautomation.com/t/problems-getting-quality-code-for-bad-tags/47577>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 8, 2021, 8:42pm UTC](https://forum.inductiveautomation.com/t/problems-getting-quality-code-for-bad-tags/47577 "2021-06-08T20:42:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 8, 2021, 8:42pm UTC](https://forum.inductiveautomation.com/t/problems-getting-quality-code-for-bad-tags/47577/1 "2021-06-08T20:42:17Z")

</div>

Ignition 8.1.7

I’m having trouble getting a valid quality code from tags that have bad quality. I made a script to browse through a tag folder/provider and print any tag path that isn’t good, excluding any that are disabled (quality code 515).

When testing this, I realized my code returns 192 for good tags (expected), but a wild negative when quality is bad (e.g. -2147483124). Code below.

I feel like I’m missing something, but if so, why I can read good quality correctly?

```auto
def get_bad_tags(path):
	results = system.tag.browse(path, {})
	for result in results.getResults():
		# skip UDT definitions
		if result['name'] == '_Types_':
			continue
		
		# recurse through folders/UDTs
		if result['hasChildren'] == True:
			get_bad_tags(result['fullPath'].toString())
			continue
		
		# print tag paths that aren't good, excluding disabled tags
		if result['tagType'].toString() == 'AtomicTag':
			print(str(result['value'].quality.getCode()))
			if result['value'].quality.isNotGood() and result['value'].quality.getCode() != 515:
				print(result['fullPath'].toString())

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4d7f8bca565117261bd1ef516b962b247fbdf187.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/4/2483f10450f7dd3c9b04db3278bf6d6f3ce0f41f.png)  
For reference, Bad 2 is Bad\_OutOfRange (524)

---

<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:** [June 8, 2021, 8:47pm UTC](https://forum.inductiveautomation.com/t/problems-getting-quality-code-for-bad-tags/47577/2 "2021-06-08T20:47:54Z")

</div>

Try using only the lower 16 bits of the code you get back, i.e. `getCode() & 0xFFFF`

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 8, 2021, 9:04pm UTC](https://forum.inductiveautomation.com/t/problems-getting-quality-code-for-bad-tags/47577/3 "2021-06-08T21:04:56Z")

</div>

Thanks, that worked! I see now it’s documented [here](http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.12/com/inductiveautomation/ignition/common/model/values/QualityCode.html) in the Javadocs, for anyone else that’s curious.

Looks like I also could have done `result['value'].quality.getName() == 'Bad_Disabled'`, which is definitely more readable.

To close the loop, this is my updated script:

```auto
def get_bad_tags(path):
	results = system.tag.browse(path, {})
	for result in results.getResults():
		# skip UDT definitions
		if result['name'] == '_Types_':
			continue
		
		# recurse through folders/UDTs
		if result['hasChildren'] == True:
			get_bad_tags(result['fullPath'].toString())
			continue
		
		# print tag paths that aren't good, excluding disabled tags
		if result['tagType'].toString() == 'AtomicTag':
			if (
				result['value'].quality.isNotGood() and
				(result['value'].quality.getCode() & 0xFFFF) != 515 # disabled
			):
				print(result['fullPath'].toString())

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 8, 2021, 9:24pm UTC](https://forum.inductiveautomation.com/t/problems-getting-quality-code-for-bad-tags/47577/4 "2021-06-08T21:24:38Z")

</div>

Another option would be to compare against one of the static final fields in `QualityCode`:

```auto
from com.inductiveautomation.ignition.common.model.values import QualityCode

		if result['tagType'].toString() == 'AtomicTag':
			if (
				result['value'].quality.isNotGood() and
				result['value'].quality.isNot(QualityCode.Bad_Disabled)
			):
				print(result['fullPath'].toString())

```
