I tried to debug that in the script editor and it closed the editor without saving. I didn't realize what happened until I re-did it and ran it again. The function should be defined before it is called, so that seems out of order.
I've never used the application builder. I do this sort of control at the script level, just before the GUI is called. Basically my scripts look like:
1. initial stuff up top
2. Main script function
3. assign dt and decide to proceed to GUI or not
4. GUI, where the ok button calls the script function.
Here's how I check for a data table. You could use a modified version of this and also check for ncol(dt) >= 2.
dtData = current data table();
try(dtData << get name, throw(New Window("No Data Table Found",<<Modal, textBOx("No open data tables found. "),textbox(" "),
ButtonBox("OK"))));