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

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.

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.

1 Like

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?

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

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

image

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

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

Probably need quotes around your fallback string.

1 Like

System should be system, case-sensitivity matters.

3 Likes

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.

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

I also tried this:

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

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

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

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?

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.

1 Like

So now I created a named query:

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

And then in component scripting, I wrote this:

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?

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. }

2 Likes

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?

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

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:

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

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]

1 Like

Add a print statement, like so:

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.

1 Like

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.

1 Like

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

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