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.
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?
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')
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.
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. }
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')
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 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.