previousValue (QualifiedValue) does not seem to work

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.

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

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.

2 Likes

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?

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

if previousValue:

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

if previousValue.value == 99 or previousValue.value is None:
    #do something
1 Like

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:

if not previousValue or previousValue.value == 99:
1 Like

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