# previousValue from change Scripts Issue

**URL:** <https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 24, 2024, 8:53pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755 "2024-10-24T20:53:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [October 24, 2024, 8:53pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/1 "2024-10-24T20:53:06Z")

</div>

so I am trying to pull the previous value from a change script but I unable to use the methods or properties associated with QualifiedValues datatype I can see if I:  
`prevV = previousValue system.perspective.print(prevV)`  
it returns `QV[[Lcom.inductiveautomation.ignition.common.model.values.QualifiedValue;@5db0174b, Good, Thu Oct 24 12:49:52 EDT 2024] `

But if i try to reference or use any of the qualified values methods it gives me this  
`AttributeError("'NoneType' object has no attribute 'getValue'",) `

This is the code that throws the error  
` prevV = previousValue.getValue() system.perspective.print(prevV)`

any ideas on why this would be happening?

---

<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:** [October 24, 2024, 8:54pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/2 "2024-10-24T20:54:47Z")

</div>

Are you checking the `initialChange` flag? There's no previous value at all when that flag is true.

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [October 24, 2024, 9:09pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/3 "2024-10-24T21:09:16Z")

</div>

Are these available when you are doing a change script on a component?  
I have a change script on an array of objects, sorry should have clarified earlier

I know they are available on tag changes, but I cannot see/find where you pass the flag for component property change scripts.

---

<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:** [October 24, 2024, 9:27pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/4 "2024-10-24T21:27:18Z")

</div>

Interesting. I hadn't noticed that there's no `initialChange` flag. But `previousValue` being null on first change makes sense. You should check for that:

```python
	if previousValue is None:
		# handle first update
	else:
		# handle change

```

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [October 24, 2024, 9:32pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/5 "2024-10-24T21:32:36Z")

</div>

Okay that makes sense, I have a property that is binded to a sql query and data being pulled is _default_ data in my databse so it should never be null.

After testing aswell your theory was correct, on the first change i get the error but the second change it returns the data.

should I have this configured differently for my use case?

---

<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:** [October 24, 2024, 9:35pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/6 "2024-10-24T21:35:58Z")

</div>

> [@Matthew\_Breeding](#):
>
> for my use case?

You haven't explained your use-case, so I don't know.

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [October 24, 2024, 9:40pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/7 "2024-10-24T21:40:18Z")

</div>

oh sorry, so I have a tables components that renders data depending what on what data is being passed, I also want the option for the user to change the data via change script. So I use an embedded view and referenced my table component. The data param for the embedded view I bind to an sql query(this is also where the change script is)

so the data will theoretically never be null initially

---

<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:** [October 24, 2024, 9:42pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/8 "2024-10-24T21:42:26Z")

</div>

I would make the property non-persistent so it always does start with a null.

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [October 24, 2024, 9:43pm UTC](https://forum.inductiveautomation.com/t/previousvalue-from-change-scripts-issue/97755/9 "2024-10-24T21:43:32Z")

</div>

Okay I will try that, thank you for the suggestion
