# Bind the Quality property of a component to an expression

**URL:** <https://forum.inductiveautomation.com/t/bind-the-quality-property-of-a-component-to-an-expression/25347>\
**Category:** General Discussion\
**Created:** [May 28, 2019, 7:52am UTC](https://forum.inductiveautomation.com/t/bind-the-quality-property-of-a-component-to-an-expression/25347 "2019-05-28T07:52:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.sluser](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mark.sluser/32/19753_2.png) [@mark.sluser](https://forum.inductiveautomation.com/u/mark.sluser)\
**Post date:** [May 28, 2019, 7:52am UTC](https://forum.inductiveautomation.com/t/bind-the-quality-property-of-a-component-to-an-expression/25347/1 "2019-05-28T07:52:38Z")

</div>

Is it possible to bind a component’s Quality property to another tag using an expression?

I have 2 tags

- Tag1 (Float)
- Tag1\_Quality (Float, 0=Good, 1=Bad)

Can the tag Tag1\_Quality drive the quality of Tag1 ?

When I use the expression to  
`ToInt({[default]PLC-1/Tag1_Quality})`

I get the error:  
`ClassCastException: Cannot coerce value '1' into type: class com.inductiveautomation.ignition.common.model.values.QualityCode`

I am using Ignition 8.0.1

Thank you,

-Mark

---

<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:** [May 28, 2019, 4:11pm UTC](https://forum.inductiveautomation.com/t/bind-the-quality-property-of-a-component-to-an-expression/25347/2 "2019-05-28T16:11:05Z")

</div>

The quality of a tag is automatically determined by its value property - what you would need to do is make Tag1 an expression tag, and use the (new to 8.0) `qualifiedValue` expression to do something like this:  
`qualifiedValue(<expression to retrieve actual value for tag>, <expression to return "Good" or "Bad">)`  
where the second argument is something like `if({Tag1_Quality}, "Good", "Bad")`.

---

<div class="post-metadata">

**Author:** ![mark.sluser](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mark.sluser/32/19753_2.png) [@mark.sluser](https://forum.inductiveautomation.com/u/mark.sluser)\
**Post date:** [May 28, 2019, 10:58pm UTC](https://forum.inductiveautomation.com/t/bind-the-quality-property-of-a-component-to-an-expression/25347/3 "2019-05-28T22:58:57Z")

</div>

Ok used your suggestion and it kind of works.  
The quality state is updating correctly, however the overlay is not reflecting the quality state.  
I have the option “Overlay Opt-Out:” turned off. So perhaps this is a bug ?

I observed:

- If “Overlay Opt-Out” is OFF, propertychange event handler is executed when a change to Tag1\_Quality occurs
- If “Overlay Opt-Out” is OFF, propertychagne event handler is NOT executed when a change to Tag1\_Quality occurs

Here is a workaround using script

if Tag1\_Quality changes, update Tag1 quality.

**Tag1\_Quality propertychange event handler**

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

if (event.propertyName == "state"):
#	print event.propertyName, " ", event.newValue
	if (event.newValue == 0):
		event.source.parent.getComponent('_').quality = QualityCode.Good
	else:
		event.source.parent.getComponent('_').quality = QualityCode.Bad

```

I also observed that if Tag1 updates, it replaces its quality with a new one.

So you also need  
**Tag1 propertychange event handler**

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

print event.propertyName, event.oldValue, event.newValue

if (event.propertyName == "dataQuality"):
	BQ_val = event.source.parent.getComponent('BQ').indicatorValue
	if (BQ_val == 0):
		BQ_quality = QualityCode.Good
	else:
		BQ_quality = QualityCode.Bad

	if (event.source.quality != BQ_quality):
		event.source.quality = BQ_quality

```

Let me know if you can get the expression binding working as it is a lot cleaner solution.

Thank you
