# Stop History for a tag when tag data is invalid

**URL:** <https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935>\
**Category:** Ignition\
**Created:** [September 1, 2019, 8:07pm UTC](https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935 "2019-09-01T20:07:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 1, 2019, 8:07pm UTC](https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935/1 "2019-09-01T20:07:32Z")

</div>

Hello

In some condition the value comes form OPC which is not valid and should not to be logged, otherwise the report would be totally wrong. For example sensor wire open for AI card and AI card send overflow value to SCADA.  
I try to use system.tag.editTag(tagPath=“Folder/Tag”,attributes={“HistoryEnabled”:True}) to stop history for the tag, but then I can’t reach even the valid history data which is recorded before in chart until I enable it again.  
So I wander how I can temporary prevent Tag History from logging data. I want similar behavior like when the tag quality is BAD and there is no data in that duration. I try to overwrite the quality to BAD but it over written by system immediately.  
what is the workaround for this kind of situation? How I can prevent logging invalid data?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 1, 2019, 9:31pm UTC](https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935/2 "2019-09-01T21:31:41Z")

</div>

Try making an expression tag that uses the forceQuality() expression function to pass the value but substitute your own quality code. That substitution can look at some other signal to decide whether to make the result good or bad. Record the expression tag instead of the original tag.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 2, 2019, 5:34am UTC](https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935/3 "2019-09-02T05:34:32Z")

</div>

Thanks  
Which one has higher performance?

1. Using your method with expression tag or
2. Same idea but trigger in tag changed event

> from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue  
> from com.inductiveautomation.ignition.common.sqltags.model.types import TagQuality  
> timestamp = system.date.now()  
> bqv = BasicQualifiedValue(2, TagQuality.BAD, timestamp)  
> system.tag.write('Kansar/FL1/val1', bqv)

Expression vs tag changed event script?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 2, 2019, 5:56pm UTC](https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935/4 "2019-09-02T17:56:12Z")

</div>

> [@nader.chinichian](#):
>
> Which one has higher performance?

I have no idea. As a general maintainability policy, I avoid event scripts when a simple expression or binding will suffice.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 1, 2020, 1:21am UTC](https://forum.inductiveautomation.com/t/stop-history-for-a-tag-when-tag-data-is-invalid/27935/5 "2020-06-01T01:21:10Z")

</div>

Also Nader, you should be using preformatted text characters ` or ``` to quote your code rather than quote blocks

 ![20200601_105055](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4bf742330e13236a0dcd987c8383bc3bb68c8fe9.jpeg)

Edit: I did it again… I need to start looking at the post dates!
