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

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:

	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?

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

The expression looks at a UDT parameter and now()

(
    (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".

try removing the initialChange check.

What happens if you change event driven to fixed?

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

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

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

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

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.

1 Like