# Gateway Tag Change Script getPreviousValue() errors?

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-getpreviousvalue-errors/53547>\
**Category:** General Discussion\
**Tags:** ignition81, scripting\
**Created:** [November 29, 2021, 8:18pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-getpreviousvalue-errors/53547 "2021-11-29T20:18:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [November 29, 2021, 8:18pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-getpreviousvalue-errors/53547/1 "2021-11-29T20:18:03Z")

</div>

I’m trying to get the previous value on the tag before it changed and . .  
All my attempts to use `getPreviousValue().getValue()` generate errors

I read through posts like these where `getPreviousValue().getValue()` is mentioned  
[change-script-triggered-with-no-reason](https://forum.inductiveautomation.com/t/gateway-tag-change-script-triggered-with-no-reason/38602)  
[gateway-tag-change-script-issue](https://forum.inductiveautomation.com/t/counter-gateway-tag-change-script-issue/37361)  
yet when I try to run `getPreviousValue().getValue()` in a script I receive the error **‘NoneType’ object has no attribute 'getValue’**

Also, looking at `getPreviousValue()` in the documentation below  
[Gateway Event Scripts Overview](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts)  
and when I run `getPreviousValue()` I see the error **‘getPreviousValue’ is not defined**

What is the correct way to get the previous value? Or perhaps I’m overlooking something obvious?

---

<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:** [November 29, 2021, 8:20pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-getpreviousvalue-errors/53547/2 "2021-11-29T20:20:48Z")

</div>

It doesn’t exist when initialChange is true. So it is null or `None` and has no `.value` property. Either check the initialChange flag or check for None.

---

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [November 29, 2021, 8:22pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-getpreviousvalue-errors/53547/3 "2021-11-29T20:22:23Z")

</div>

That must be the cause of my problem then. I’m triggering the event by saving the script
