# previousValue (QualifiedValue) does not seem to work

**URL:** <https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [February 21, 2023, 12:38am UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091 "2023-02-21T00:38:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [February 21, 2023, 12:38am UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/1 "2023-02-21T00:38:21Z")

</div>

I have a strange thing going on.  
I have 2 custom properties. 1 called Group1 and 1 called Group1Previous.  
Basically what I want to do is update the Group1Previous with the previous value of Group1.  
There are some reasons why I want to do this, that I am not explaining right now, unless somebody want to know. But I do not think it is relevant.

If I use currentValue.value, the code works as I expected.  
If I replace currentValue with previousValue this does not work anymore.  
Error running property change script on session.custom.Group1: Traceback (most recent call last): File "function:valueChanged", line 2, in valueChanged AttributeError: 'NoneType' object has no attribute 'value'  
What am I doing wrong? Any help would be appreciated.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/a/da50640bf5b0fb8edf519fd0c92f9d42019fdf3e.png)

---

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [February 21, 2023, 12:39am UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/2 "2023-02-21T00:39:35Z")

</div>

I forgot to say that I am using Ignition edge version 8.1 with Perspective.

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [February 21, 2023, 1:25am UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/3 "2023-02-21T01:25:46Z")

</div>

When your session loads for the first time the property has not yet had a value, so previousValue is None. Your script will work in future executions, it will just error out the first time. You just need to add a 'previousValue is not None' check to your if statement.

---

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [February 21, 2023, 3:24pm UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/4 "2023-02-21T15:24:04Z")

</div>

Thank you Amy. That makes sense, but I still am having issues.  
I created at the session 2 custom properties.  
Group1 and Group1Previous.  
so if Group1 changes it should write the previous state to Group1Previous.  
But it does noy like that I use the ".Value" even though it lets me select it?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/178488908c878c9063f1d7a98fc9673820ba3292.png)

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [February 21, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/5 "2023-02-21T15:42:12Z")

</div>

You want to make sure `previousValue` is something, not nothing. So something like this:

```auto
if previousValue:

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 21, 2023, 4:18pm UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/6 "2023-02-21T16:18:39Z")

</div>

When you check for python's `None`, you don't use quotes. The quotes make it a string which is not the _ **None type** _

```python
if previousValue.value == 99 or previousValue.value is None:
    #do something

```

---

<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:** [February 21, 2023, 4:41pm UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/7 "2023-02-21T16:41:33Z")

</div>

> [@dkhayes117](#):
>
> `if previousValue.value == 99 or previousValue.value is None`

Two mistakes here:

1. Dereferencing `.value` before checking for `None`, and
2. Checking `.value` for `None` when you need to check `previousValue` itself.

The simplest syntax is:

```python
if not previousValue or previousValue.value == 99:

```

---

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [February 21, 2023, 4:50pm UTC](https://forum.inductiveautomation.com/t/previousvalue-qualifiedvalue-does-not-seem-to-work/70091/8 "2023-02-21T16:50:06Z")

</div>

Yes, that works.  
Thank you for the help.  
here is the final solution after the suggestions above.

def valueChanged(self, previousValue, currentValue, origin, missedEvents):  
if not previousValue or previousValue.value == 99:  
self.custom.Group1Previous = 0  
else:  
self.custom.Group1Previous = previousValue.value
