Gateway tag change script - previous value not available

In tag event scripts, previousValue is available in the valueChanged event function but it doesn’t appear to be available in a gateway event tag change script. Is there a way to get the previous value from there?

Version: 8.0.2

1 Like

Looks like it should be available as event.previousValue. This will return the previous value as a qualified value, if you want just the actual value you can use event.previousValue.value

Hi,

I was just trying to use your suggestion for comparing the current value and previous value on gateway event script tag change for event. enclosing the my script for your reference and the same it gives an error( that is also enclosed). Please resolve this issue.

My Script:

Tag is of Int4 Datatype

if newValue.getValue() != event.previousValue.value:
        <Some Code>

Error:

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 2, in AttributeError: 'NoneType' object has no attribute 'value'

at org.python.core.Py.AttributeError(Py.java:173)

at org.python.core.PyObject.noAttributeError(PyObject.java:930)

at org.python.core.PyObject.__getattr__(PyObject.java:925)

at org.python.pycode._pyx1379.f$0(:67)

at org.python.pycode._pyx1379.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:165)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1275)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:603)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:192)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:135)

at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:96)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 2, in AttributeError: 'NoneType' object has no attribute 'value'

... 18 common frames omitted

There is no previous value when the initialChange flag is true. Either check this flag or check if previousValue is None before further dereferencing it.

What is a solution when there is not initialChange argument?

I have defined session custom tag (A), and I need to set some other session custom tags in depends on the combination current and previous value of session custom tag (A)? In this case, value change on session tags, there is no argument that I can use for detecting initial change?