# Tag Change Script Not Firing on Expression Tag - Works Fine on Memory Tag

**URL:** <https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [October 4, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834 "2024-10-04T15:33:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [October 4, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/1 "2024-10-04T15:33:57Z")

</div>

I’m running into a strange issue with a tag change script on an expression tag in Ignition. The script is supposed to run when the value of the tag becomes `True`. However, the script never fires when the tag type is set to "Expression." But when I switch the tag to a memory tag and manually set the value to `True`, the script runs perfectly.

Here's the code:

```python
	if not initialChange and previousValue.quality.isGood() and currentValue.quality.isGood():
		if currentValue.value:
			# do something..

```

The value is the same in both cases, so I’m not sure why the script won’t execute when it’s an expression tag. Are tag change scripts handled differently for expression tags, or am I missing something?

---

<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:** [October 4, 2024, 3:35pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/2 "2024-10-04T15:35:36Z")

</div>

What do you have that triggers the expression's re-execution?

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [October 4, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/3 "2024-10-04T15:49:18Z")

</div>

The expression looks at a UDT parameter and now()

```python
(
    (indexOf({DemandPoll}, "_AD") != -1 && getHour24(now()) = 9 && (getDayOfWeek(now()) = 2 || getDayOfMonth(now()) = 1))
)
||
(
    (indexOf({DemandPoll}, "_DD") != -1 && !(getDayOfWeek(now()) = 2 || getDayOfMonth(now()) = 1) && getHour24(now()) = 9)
)

```

The execution mode is set to "Event Driven".

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 4, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/4 "2024-10-04T16:04:47Z")

</div>

try removing the `initialChange` check.

What happens if you change event driven to fixed?

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [October 4, 2024, 4:08pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/5 "2024-10-04T16:08:16Z")

</div>

Removing the `initialChange` check fixed the issue. What would the impact of that be? Could it lead to unintended behavior in certain scenarios?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 4, 2024, 4:10pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/6 "2024-10-04T16:10:30Z")

</div>

I would think that the initial change condition would inherently also mean that `previousValue.quality.isGood()` would be false, right?

If that's the case, you should be safe

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [October 4, 2024, 4:11pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/7 "2024-10-04T16:11:58Z")

</div>

Out of curiosity, why does removing that condition make it work? Is `initialChange` always True in expression tags?

---

<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:** [October 4, 2024, 4:16pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/8 "2024-10-04T16:16:20Z")

</div>

> [@mdia](#):
>
> What would the impact of that be?

`previousValue` will be null (Python `None`) when initialChange is true. Which will break your `if` statement.

---

<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:** [October 4, 2024, 4:20pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-firing-on-expression-tag-works-fine-on-memory-tag/96834/9 "2024-10-04T16:20:21Z")

</div>

> [@mdia](#):
>
> Is `initialChange` always True in expression tags?

No, but when restarting a tag, it is possible (likely, even) for a truly new value to be delivered with `initialChange` true, in which case you won't get an event with that value separately.

When the initial change flag is true, it means "I can't tell you anything about any previous value", and you have to fall back on other persistence if you need to identify a new value that arrives in that event.

You should not unconditionally ignore the initial change.
