Gracefully exiting an add-inI am writing an add-in to operate on the Current Data Table(). I want the add-in to exit gracefully without doing anything if:
(a) there is no Current Data Table()
or
(b) the Current Data Table has <2 columns.
I can't seem to get this to happen. I installed the add-in and looked at the .jmpcust file that was generated. Up at the very top of the script where the comment says "Variables and functions declared here are scoped to the Application namespace", I note this code:
dt = Current Data Table();
If(Is Empty(dt),
Quit Application()
);
Quit Application = Function({},
Current Window() << Close Window;
Throw()
)which I *think* was inserted by Application Builder (and not by me).
It would seem to be right for accomplishing (a), but instead my add-in charges ahead in the absence of a Current Data Table() and opens its dialog window.
Can someone help me out?
ScriptingRe: Gracefully exiting an add-inI 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></MODAL>
Re: Gracefully exiting an add-inI think I found a solution in the meantime looking at one of txnelson's posts. In the application script, I put:
If( N Table() == 0,
Throw( "Add-in requires an open data table." )
);
dt = Current Data Table();
If( N Cols( dt ) < 2,
Throw(
"Add-in requires a table with at least two columns."
)
);