# How to open a pop up based on null result of a named query binding?

**URL:** <https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205>\
**Category:** Ignition\
**Created:** [September 21, 2021, 7:44pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205 "2021-09-21T19:44:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 21, 2021, 7:44pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/1 "2021-09-21T19:44:10Z")

</div>

I have a query tag and I want to write a script to open a pop up if its value is null or better to say when the database do not return any value.

Alternatively, I can have a label and bind its value to an SQL query and write ‘Error’ value in its fall back value box and use that to open the pop up.

Not sure which way works better. I tried the first one but it did not work and for the 2nd option I used the property change event but it seems that it is not working properly.

---

<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:** [September 21, 2021, 7:47pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/2 "2021-09-21T19:47:15Z")

</div>

A regular query will return a dataset with zero rows if nothing matches your where clause. There’s no fallback because that can be a legitimate result. A scalar query is expected to return at least one row and one column, so that [0,0] can be retrieved. No rows =\> fallback.

You can look at a dataset’s length (`.rowCount` in jython) to do any partial-result or no-result handling you need.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 21, 2021, 7:56pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/3 "2021-09-21T19:56:13Z")

</div>

If I want to write a script to open the pop-up when only returns no rows, what would be the best place to do that? In that case, do I still need to check for the length of returned value?

---

<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:** [September 21, 2021, 7:58pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/4 "2021-09-21T19:58:13Z")

</div>

Use a propertyChange event monitoring the property where the data arrives.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 21, 2021, 8:05pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/5 "2021-09-21T20:05:55Z")

</div>

I have the below fall back value for the text property of my label:

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

I also wrote the script below, but it is not working. Am I missing something here? The pop up window name is ‘Error’

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

```auto
if event.propertyName == 'Text':
	if event.source.text== 'Error':
		System.nav.openwindow('Error')

```

---

<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:** [September 21, 2021, 8:08pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/6 "2021-09-21T20:08:27Z")

</div>

Probably need quotes around your fallback string.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 21, 2021, 10:02pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/7 "2021-09-21T22:02:51Z")

</div>

`System` should be `system`, case-sensitivity matters.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 22, 2021, 3:11am UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/8 "2021-09-22T03:11:50Z")

</div>

I tried this on the client tag change script. This script is triggered by a query tag. it is working but only one time. So for example, if the query tag returns null twice in a row, the pop-up does not show up the 2nd time. Am I doing something wrong here? Basically, I want to open the pop up whenever the value is null even if we have more than one null in a row.

```auto
	if previousValue != currentValue.value:
		CrValue=currentValue.value
		if CrValue is None:
			system.nav.openWindow('Error')

```

I also tried this:

```auto
if currentValue.value is None:
   system.nav.openWindow('Error')

```

---

<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:** [September 22, 2021, 11:50am UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/9 "2021-09-22T11:50:50Z")

</div>

`previousValue` is also a qualifiedValue so your if statement should be:

```auto
if previousValue.value != currentValue.value:
    CrValue = currentValue.value
    if CrValue is None:
        system.nav.openWindow('Error')

```

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 22, 2021, 12:14pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/10 "2021-09-22T12:14:45Z")

</div>

You are correct!  
In this application we may have multiple “null” values in a row, so the value may not change a couple of times and remains “null”. Is there any way to open that pop-up whenever the value is “null” regardless of value change?

---

<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:** [September 22, 2021, 12:28pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/11 "2021-09-22T12:28:33Z")

</div>

Don’t use a scalar query. That can only deliver the one value, and you cannot distinguish the result of one query from another if the value is the same.

Use a regular or named query binding with a dataset result. The dataset will be unique for each result even if the content is identical. The propertyChange event for the dataset property will fire each time the data arrives, and your logic to check for no rows or a null will work every time.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 22, 2021, 1:40pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/13 "2021-09-22T13:40:27Z")

</div>

So now I created a named query:

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

And I am using its result and bound it to the text property of my label component.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2e3095741d29473da1f1d89a136cd723c797822f.png)

And then in component scripting, I wrote this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/0/f09ef98527b0265a137753efaf02b0fb95d06143.png)

```auto
if event.propertyName == 'Text':
	if event.source.text is None:
		System.nav.openwindow('Error')

```

But it is not working and I get errors. I know I am doing something wrong here. Probably in component scripting but not sure if the process even is correct here or not. This is how I should check to see if the dataset reurns no row?

---

<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:** [September 22, 2021, 2:29pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/14 "2021-09-22T14:29:04Z")

</div>

> [@pkhoshroo](#):
>
> bound it to the text property

No, that is a string property. You need a dataset property. Make a custom one. Bind your query there. Bind your text property to `try({Root Container.path.to.custom.property}[0,0], '')`. That will transfer your scalar for display, or an empty string when no row.

Then you use the property change event _ **monitoring the custom property** _ to decide when you need to open the popup.

{ BTW: have you completed Inductive University yet? It covers these basics about bindings. }

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 22, 2021, 4:47pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/15 "2021-09-22T16:47:26Z")

</div>

Thank you very much, Phill. Appreciate the great information you share. I learned something new!!! I knew that we can create custom properties but I forgot to use them here!!

I completed the Inductive course, however, that was a couple of months ago, I have to get back to that to refresh my memories.

I went through multiple threads to understand how I can check for the dataset data and if that is null or not, but could not find anything that is relevant to my work. I probably cannot use the same script shown below again, but I remember you said something about row count and doing partial-result or no-result handling. Not quite sure how to apply this. There is a " [system.dataset.toPyDataSet]" too that I can use to change my dataset to PyDataset, but would this be a good way to tackle this issue?

```auto
if event.propertyName == "querydata":
	if event.source.querydata is None:
		System.nav.openwindow('Error')

```

---

<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:** [September 22, 2021, 4:52pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/16 "2021-09-22T16:52:16Z")

</div>

A query result, as long as the query completes, won’t ever be null itself. It just won’t have rows. Your test would be something like this:

```auto
if event.propertyName == "querydata":
	if event.newValue.rowCount == 0:
		System.nav.openwindow('Error')

```

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 22, 2021, 4:58pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/17 "2021-09-22T16:58:21Z")

</div>

Thank you very much, Phill! @pturmel  
The code seems to be not working in the way we expected. Now the ‘Error’ window pops up every time the value is changed, regardless of being null or having data.

I used this one instead:

if event.newValue.getRowCount() == 0:

It seems to be working however when I close the pop up, the pop up opens again unless the dataset is changed to a correct value.

So just a background, the data that I get from the dataset is  
[1R x 1C]  
or  
[2R x 1C]  
or  
[3R x 1C]

if I do not get any data it would be:  
[0R x 1C]

---

<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:** [September 22, 2021, 6:05pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/18 "2021-09-22T18:05:36Z")

</div>

> [@pkhoshroo](#):
>
> Now the ‘Error’ window pops up every time the value is changed, regardless of being null or having data.

Add a print statement, like so:

```auto
if event.propertyName == "querydata":
	print event.newValue
	if event.newValue.rowCount == 0:
		system.nav.openWindow('Error')

```

Also, methods like `.getRowCount()` that follow the NetBeans getter/setter naming standard are automatically available in jython as the corresponding NetBeans property. So `.rowCount` is equivalent.

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [September 22, 2021, 6:49pm UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/19 "2021-09-22T18:49:20Z")

</div>

I belive it’s triggering the popup again due to relative query polling.

Try setting the polling OFF as it’d anyway trigger the query when any of query parameter changes its value.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 23, 2021, 2:36am UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/20 "2021-09-23T02:36:27Z")

</div>

Thank you very much, Phill. I used the same code you provided and set the polling mode to off.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [September 23, 2021, 2:37am UTC](https://forum.inductiveautomation.com/t/how-to-open-a-pop-up-based-on-null-result-of-a-named-query-binding/51205/21 "2021-09-23T02:37:01Z")

</div>

It worked!!! Thank you very much!!! I did not think about this 🙂
