List Selection: protect from no value selected

This post (http://www.inductiveautomation.com/forum/viewtopic.php?f=23&t=2716&p=3623#p3623) shows how to use an expression and script to protect against running code when no item is selected in a drop down list. Along these lines, I have a dynamic property bound to the selected value - the property is an SQL query with the WHERE clause coming from the list selection. Can anyone point me in the direction of protecting this property from executing if nothing is selected? The property binding is binding types -> Database -> SQL Query. Where would I put suitable if/then statements for protection?

Also, the script playground is a nice feature. How can I access objects on my pages (like with event.source… etc)? I would use the tool more if I could get access to my datasets and such that I already have set up.

In this case you would usually just fill in the fallback value of the query binding. The fallback value will be used when the query returns no rows.

Glad you like the script playground. As far as experimenting with buttons goes, typically you’d just throw a button on your window and have it output to the console.

Thanks… but pardon my ignorance. Where is the fallback value selected? That sounds exactly what I am looking for.

Also… where is the console? I thought I might be able to use ‘print’ statements in my scripts for debugging, but don’t know where stdout might be… or how to even change the filehandle for output.

The fallback value is specified right underneath the SQL query in the “SQL Query” property binding dialog. there is a checkbox there that says “Use Fallback Value”.

The console is available through the Diagnostics window (Under the help menu), and in the Designer, under View > Panels > Output Console.

Hope this helps,

Sorry… not getting it today. Where is this checkbox?


Ah, well, you’re binding to a dataset. When binding to a dataset, you don’t need a fallback value, since an empty dataset is a perfectly legal value. If you want some other dataset instead of an empty dataset on an empty selection, make a dynamic property (lets call it “EmptyDataset”, fill it with the values you’d like to see, and bind whatever dataset this is trying to fill in to an expression like:

if( len({Film1.Root Container.Dropdown 2.SelectedRecipeDS})=0, {Film1.Root Container.Dropdown 2.EmptyDataset}, {Film1.Root Container.Dropdown 2.SelectedRecipeDS} )