# How to check for NoneType in a Change Script

**URL:** <https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 10, 2022, 9:04pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370 "2022-11-10T21:04:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 10, 2022, 9:04pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/1 "2022-11-10T21:04:31Z")

</div>

![help0](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/b/5b2aa7c8287fca421d06d8a8ef34f46f2ba24f3e.png)  
 ![help1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/58d84b2ee4208da70ed91e023102cc5d1df4869a.png)

I was wondering how to avoid the error above when the props.series[0].data Dataset is empty. Any help would be appreciated!

\<  
def valueChanged(self, previousValue, currentValue, origin, missedEvents):  
if self.props.series[0].data != None:  
if previousValue \< currentValue:  
self.props.plots[0].axes[0].min = CustomTrends.getMinimum(self.props.series[0].data)  
self.props.plots[0].axes[0].max = CustomTrends.getMaximum(self.props.series[0].data)\*1.06

>

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 10, 2022, 9:06pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/2 "2022-11-10T21:06:32Z")

</div>

Try  
`if self.props.series[0].data is not None:`

* * *

Tip: please post code rather than pictures of code and format it using the \</\> button. It means people can copy the code to test it and paste it into their answers to edit it rather than typing the whole lot out again. Post a screengrab as well if it adds some important details.

---

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 10, 2022, 9:09pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/3 "2022-11-10T21:09:23Z")

</div>

Thank you, I edited my post to include the code

---

<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:** [November 10, 2022, 9:10pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/4 "2022-11-10T21:10:02Z")

</div>

You should be able to check it simply by using

```auto
if self.props.series[0].data:
    ...

```

---

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 10, 2022, 9:25pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/5 "2022-11-10T21:25:40Z")

</div>

Even with either _'if self.props.series[0].data: '_ or _'if self.props.series[0].data is not None: '_ I am getting the same error on line 5 when the DataSet is empty.

---

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 10, 2022, 9:29pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/6 "2022-11-10T21:29:59Z")

</div>

![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/2/c2163b07445d889fa5cb90ec5a13ec445e734c8d.png)

---

<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:** [November 10, 2022, 9:34pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/7 "2022-11-10T21:34:37Z")

</div>

A dataset with no rows is not the same thing as `None`.  
Do this instead

```nohighlight
if self.props.series[0].data.getRowCount():

```

---

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 10, 2022, 9:48pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/8 "2022-11-10T21:48:16Z")

</div>

It produces this error on line 2 now.  
Error running property change script on TimeSeriesChart.props.series[0].data: Traceback (most recent call last): File "function:valueChanged", line 2, in valueChanged AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'getRowCount'  
Code:

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if self.props.series[0].data.getRowCount():
		if previousValue < currentValue:
			self.props.plots[0].axes[0].min = CustomTrends.getMinimum(self.props.series[0].data)
			self.props.plots[0].axes[0].max = CustomTrends.getMaximum(self.props.series[0].data) * 1.06

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 10, 2022, 9:50pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/9 "2022-11-10T21:50:58Z")

</div>

... using the \</\> button to format the code. Select the code and press the button.

---

<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:** [November 10, 2022, 9:53pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/10 "2022-11-10T21:53:36Z")

</div>

what is the result of doing

```python
system.perspective.print(type(self.props.series[0].data))

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 10, 2022, 10:03pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/11 "2022-11-10T22:03:52Z")

</div>

Better might be to check for both None Type and an Empty Data set.

```auto
if self.props.seris[0].data is not None and self.props.series[0].data.rowCount:

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 10, 2022, 10:10pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/12 "2022-11-10T22:10:07Z")

</div>

previousValue and currentValue are `QualifiedValue` objects, so you need to get the value out of them.

`previousVaue < currentValue` will probably always evaluate as false.  
~~  
I would probably do something like:~~

~~ 

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if all([previousValue, currentValue,self.props.series[0].data,self.props.series[0].data.rowCount, previousValue.value < currentValue.value]):
		self.props.plots[0].axes[0].min = CustomTrends.getMinimum(self.props.series[0].data)
		self.props.plots[0].axes[0].max = CustomTrends.getMaximum(self.props.series[0].data) * 1.06

```

 ~~

EDIT: Code does not work when tested. Mainly because you can't compare datasets with `<`.

---

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 10, 2022, 10:14pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/13 "2022-11-10T22:14:44Z")

</div>

This is the result:  
`16:13:53.939 [Browser Thread: 54158] INFO Perspective.Designer.Workspace - class com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ArrayWrapper`

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 11, 2022, 2:09am UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/14 "2022-11-11T02:09:34Z")

</div>

Okay, lets back up a few steps and make sure that we understand everything.

1. The error that you were originally encountering on Line 5 was saying that `*` operator is not supported on `NoneType`, in the context of your code, this means that `CustomTrends.getMaximum()` returned a NoneType object. Can you provide the code for this method?

2. If I run `system.perspective.print(type(self.props.series[0].data))` on a this, while it contains a dataset object, the output I see in the console is

```nohighlight
class com.inductiveautomation.ignition.common.JsonDataset

```

So, either you're object isn't what you thought it is, or your code doesn't match what @dkhayes117 provided.

Assuming that the functions `CustomTrends.getMinimum()` and `CustomTrends.getMaximum()` do something like:

```python
def getMinimum(ds):
    #ds is expected to be a Dataset type object
    return min(ds.getColumnAsList(ds.getColumnIndex('column')))

def getMaximum(ds):
    #ds is expected to be a Dataset type object
    return max(ds.getColumnAsList(ds.getColumnIndex('column')))

```

Then the following code properly checks that this is a true valueChange and that the dataset is not empty.

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if all([previousValue, currentValue,currentValue.value,currentValue.value.rowCount]):
		self.props.plots[0].axes[0].min = CustomTrends.getMinimum(currentValue.value)
		self.props.plots[0].axes[0].max = CustomTrends.getMaximum(currentValue.value) * 1.06

```

However, why not just use expression bindings here:

```nohighlight
coalesce(min({this.props.series[0].data},'ColumnName'),100)

```

```nohighlight
coalesce(max({this.props.series[0].data},'ColumnName'),100) * 1.06

```

These expressions will return the min/max if there is data, and the provided default value otherwise.

---

<div class="post-metadata">

**Author:** ![Logan\_Krohn](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Logan\_Krohn](https://forum.inductiveautomation.com/u/Logan_Krohn)\
**Post date:** [November 11, 2022, 8:38pm UTC](https://forum.inductiveautomation.com/t/how-to-check-for-nonetype-in-a-change-script/66370/15 "2022-11-11T20:38:49Z")

</div>

My .getMinimum and getMaximum functions were returning null for empty datasets. Also the code you added for checking was helpful.
