# Gateway scripting - previous value

**URL:** <https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568>\
**Category:** Ignition\
**Created:** [September 27, 2022, 8:35pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568 "2022-09-27T20:35:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfredo\_Egmo](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Alfredo\_Egmo](https://forum.inductiveautomation.com/u/Alfredo_Egmo)\
**Post date:** [September 27, 2022, 8:35pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/1 "2022-09-27T20:35:34Z")

</div>

Is there a way to get the Previous Value in a Gateway Event Script? the next line below is not working…  
thanks

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/87134ec3447a06adf73ef39356dc219c98066393.png)

---

<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:** [September 27, 2022, 8:39pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/2 "2022-09-27T20:39:18Z")

</div>

What doesn’t work about it?

Keep in mind the first time the script executes there is no previous value, so it will be null / Python `None`, which you need to check for before you try to access its value component.

---

<div class="post-metadata">

**Author:** ![Alfredo\_Egmo](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Alfredo\_Egmo](https://forum.inductiveautomation.com/u/Alfredo_Egmo)\
**Post date:** [September 27, 2022, 8:44pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/3 "2022-09-27T20:44:20Z")

</div>

It shows this Error

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/2/1216b63d12f661377a9ef75c30988c1f69b52264.png)

---

<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:** [September 27, 2022, 8:46pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/4 "2022-09-27T20:46:26Z")

</div>

Ok, that’s caused by what I warned about.

You need to a check like this before accessing the previous value:

```auto
if event.getPreviousValue() is not None:
    # ... do stuff that requires the previous value 

```

---

<div class="post-metadata">

**Author:** ![Alfredo\_Egmo](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Alfredo\_Egmo](https://forum.inductiveautomation.com/u/Alfredo_Egmo)\
**Post date:** [September 27, 2022, 8:50pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/5 "2022-09-27T20:50:29Z")

</div>

thanks that worked.

---

<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 27, 2022, 9:04pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/6 "2022-09-27T21:04:24Z")

</div>

More generally, you can check the `initialChange` flag. When true, there won’t be a previous value.
