# Gateway tag change script - previous value not available

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055>\
**Category:** Ignition Early Access\
**Created:** [July 31, 2019, 7:35pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055 "2019-07-31T19:35:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CraigP](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CraigP](https://forum.inductiveautomation.com/u/CraigP)\
**Post date:** [July 31, 2019, 7:35pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055/1 "2019-07-31T19:35:20Z")

</div>

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**

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [July 31, 2019, 10:12pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055/2 "2019-07-31T22:12:45Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![harigobu.gb](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@harigobu.gb](https://forum.inductiveautomation.com/u/harigobu.gb)\
**Post date:** [November 17, 2019, 6:04pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055/3 "2019-11-17T18:04:20Z")

</div>

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

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

```

Error:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 17, 2019, 6:19pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055/4 "2019-11-17T18:19:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maja](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@maja](https://forum.inductiveautomation.com/u/maja)\
**Post date:** [October 1, 2020, 9:36pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-previous-value-not-available/27055/5 "2020-10-01T21:36:42Z")

</div>

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?
