# Dataset Cannot Be Null Error when window is first opened

**URL:** <https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [August 17, 2020, 10:41am UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797 "2020-08-17T10:41:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_S](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bill_s/32/6705_2.png) [@Bill\_S](https://forum.inductiveautomation.com/u/Bill_S)\
**Post date:** [August 17, 2020, 10:41am UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/1 "2020-08-17T10:41:39Z")

</div>

Ignition 8.0.5

I get the following error 6 to 10 times when I open a window the first time after launching the Vision project:

Traceback (most recent call last):  
File “event:propertyChange”, line 5, in   
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Dataset can not be null

Ignition v8.0.5 (b2019101516)  
Java: Azul Systems, Inc. 11.0.4

If I move to another window in the project and then come back, the error does not happen. Also, it won’t happen when I run the script in designer. Also it seems to function perfectly except for the errors.

The script is short:

1 event.source.parent.getComponent(‘MES Analysis Controller’).refresh()  
2 # Get the dataset from the MES Controller and make a dataset called “data”  
3 data = event.source.parent.getComponent(“MES Analysis Controller”).data  
4  
5 formattedData = system.dataset.formatDates(data, “H:m”)  
6 table = event.source.parent.getComponent(‘table’)  
7 table.data = formattedData

I’ve run this in designer by triggering with pushbuttons and printing the datasets to the console, but it’s never null when I do that.

I feel like I’m missing something really obvious here. Does anyone see anything obviously wrong?

Thanks.

---

<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:** [August 17, 2020, 12:09pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/2 "2020-08-17T12:09:30Z")

</div>

First of all, using this in a property change event, you need to filter out the property change you want to act on. Since you are getting the error 6 to 10 times, that is the number of properties that are changing, therefore your script is running once for each property. Narrow it down to the exact case you want then see if your error returns,

```auto
if event.propertyName == 'data':
  do script...

```

---

<div class="post-metadata">

**Author:** ![Bill\_S](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bill_s/32/6705_2.png) [@Bill\_S](https://forum.inductiveautomation.com/u/Bill_S)\
**Post date:** [August 17, 2020, 4:58pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/3 "2020-08-17T16:58:36Z")

</div>

dkhayes, thanks for your reply. I totally missed that and that seems to have solved the issue.

Thank you!!!

---

<div class="post-metadata">

**Author:** ![Bill\_S](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bill_s/32/6705_2.png) [@Bill\_S](https://forum.inductiveautomation.com/u/Bill_S)\
**Post date:** [August 17, 2020, 5:55pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/4 "2020-08-17T17:55:26Z")

</div>

I spoke too soon…I still get the error.

Is there something different about running the project that would explain why I can’t reproduce this in Designer?

---

<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:** [August 17, 2020, 6:04pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/5 "2020-08-17T18:04:19Z")

</div>

I have no idea about the MES controller or how it works, but I would check permissions on the project. It may have to do with the _Legacy Database Access_ permissions or something related to that. The permissions are under project properties-\>Client-\>Permissions

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [August 17, 2020, 6:36pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/6 "2020-08-17T18:36:08Z")

</div>

It sounds like your script is running before `MES Analysis Controller.data` is populated. You could add `if data != None` on line 4 and indent lines 5-7 under that so they only run if data is not None.

---

<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:** [August 17, 2020, 6:37pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/7 "2020-08-17T18:37:38Z")

</div>

Why not…

```auto
data = event.source.parent.getComponent(“MES Analysis Controller”).data
if event.propertyName == 'data' and data != None:
  do script...

```

Looks like I was too slow.

---

<div class="post-metadata">

**Author:** ![jonathan.taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonathan.taylor/32/4048_2.png) [@jonathan.taylor](https://forum.inductiveautomation.com/u/jonathan.taylor)\
**Post date:** [August 17, 2020, 6:52pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/8 "2020-08-17T18:52:58Z")

</div>

Perhaps there’s a better way. The MES Analysis Controller has an afterUpdate extension function that fires once the data has been refreshed. Running a script from that function would seem to be more logical and will more reliably give you non-null data.

---

<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:** [August 17, 2020, 8:22pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/9 "2020-08-17T20:22:57Z")

</div>

Just for the record I would have this script below, so the data isn’t assigned on every single property change event

```auto
if event.propertyName == 'data':
  data = event.source.parent.getComponent('MES Analysis Controller').data
  if data:
    do script...
```

---

<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:** [August 17, 2020, 8:34pm UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/10 "2020-08-17T20:34:30Z")

</div>

Be careful! `None` behaves oddly in comparisons. Best to rely on the implicit conversion of objects to **True** , like so:

```auto
if event.propertyName == 'data':
  data = event.source.parent.getComponent("MES Analysis Controller").data
  if data:
    do script...

```

And watch out for those curly quotes you copied…

---

<div class="post-metadata">

**Author:** ![Bill\_S](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bill_s/32/6705_2.png) [@Bill\_S](https://forum.inductiveautomation.com/u/Bill_S)\
**Post date:** [August 18, 2020, 2:49am UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/11 "2020-08-18T02:49:31Z")

</div>

Phil, that did the trick!

I still don’t understand why I don’t see the error in Designer, but that fixed it.

Thank you all so much.

---

<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:** [August 18, 2020, 2:58am UTC](https://forum.inductiveautomation.com/t/dataset-cannot-be-null-error-when-window-is-first-opened/37797/12 "2020-08-18T02:58:31Z")

</div>

Thanks for the insight Phil!
