Re: Column() vs As Column() vs datable:column vs dt:As name("column")Nice video tutorial about the differences between column() and as column():
Most Common JSL Mistakes and How to Avoid Them (2020-US-30MP-571)
(starting @ 5:18 min)
with the example
dt << Select Where( Column( colName )[Row()] == 14 );
dt << Select Where( As Column( colName ) == 14 );
Concerning
How one would use all of these methods to make a JSL script robust to column name changes?
How about an error handling feature which catches missing-column-events after column name changes - with an option to auto-fix the code.
The idea:
In case of a missing column, instead of showing an error message, JMP could open a window with a column list to pick the correct one.
Then the execution of the code could continue to run - and the source code could be fixed automatically.
edit: direct link to the video
https://community.jmp.com/t5/Abstracts/Most-Common-JSL-Mistakes-and-How-to-Avoid-Them-2020-US-30MP-571/ev-p/758506/redirect_from_archived_page/true#U281519
[the link on top doesn't get displayed with every browser]
Re: Column() vs As Column() vs datable:column vs dt:As name("column")Best reference (outside of my own experience and lots and lots of trial and error) is from scripting index:


Help pages is other place Column(- , "name", "formatted") and
As Column(name). This also has some information Scripting Guide > JSL Building Blocks > Rules for Name Resolution > Frequently Asked Questions about Name Resolution and Scripting Guide > Data Tables > Columns > Send Messages to Data Column Objects also Iterate on Rows in a Table , so basically the documentation (especially Scripting Guide).
Re: Column() vs As Column() vs datable:column vs dt:As name("column")Could you please include in your answer a reference that explains this bit?
"As Column() "accesses" a column (what this means depends on the case...)."
Re: Column() vs As Column() vs datable:column vs dt:As name("column")I don't usually like +1 posts, but @jthi this is the exact same methodology I do for production scripts. I usually think about it like
Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");
col_name = "age";
show(ismissing(AsColumn(dt, col_name)) & ismissing(dt:age)); // these are both the same as far as I know
cols = dt << get column references; // these are the actual references
show(cols[2] == Column(dt, col_name)); // these are references
Re: Column() vs As Column() vs datable:column vs dt:As name("column")This is a bit long post and jumping here and there, sorry about that..
As Column(), Column(), :colname, ... isn't simple in JSL and which to use depends on the case. My preferred method is to always use (except when I cannot or if I want a bit cleaner look in script) Column(datatable_reference, "string of the name of the column"). :colname does have it's benefits which can be sometimes used for scripters benefit (some are mentioned here Scripting Guide > JSL Building Blocks > Rules for Name Resolution > Rules for Resolving Names in Exceptions section).
I also like to use strings of column names instead of :colname syntax to avoid some issues that might happen here and there. For example << Get Column Names("String") instead of just << Get Column Names() and then I get the reference with Column(string) if needed.
Column(- , "name", "formatted") and
As Column(name) are not same. Column() returns you a reference to column and As Column "accesses" a column (what this means depends on the case...). When you first run this script dt:timestamp will return missing value, as the Row() hasn't been properly defined for JMP's indexing (it is initialized as 0).
View more...
@ih has some good suggestions on how to manage name changes in columns. Also when inserting columns to for example Graph Builder, you can use Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute and sometimes Eval(). << Get Name can also be helpful from time to time or building user interface with Filter Col Selector / Col List Box for example (like @pauldeen suggested).
Re: Column() vs As Column() vs datable:column vs dt:As name("column")How would you know which column the script should reference? If you really need to monitor for column name changes you could do that by subscribing to changes in the table and recording those column names somewhere, but I think that would be pretty complex. Could you instead define a column property and search for that?
Subscribe example from Scripting Guide:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
f = Function( {dtab, col, oldname},
Print( dtab << getname() );
Print( "new column name", (col << getname()) );
Print( "old name", oldname );
);
sub = dt << Subscribe( "", OnRenameColumn( f ) );
Column( dt, 1 ) << set name( "test" );
Wait( 1 );
dt << unsubscribe( sub, on rename column );
Use column property
Names Default To Here( 1 );
dt = Open( "$Sample_data/big class.jmp" );
dt:height << Set Property( "My Script Identifier", X );
XVar = Filter Each({c}, dt << Get Column References,
ident = char(c << Get Property( "My Script Identifier" ));
if( is empty(ident), 0, ident == "X", 1, 0)
)[1];Re: Column() vs As Column() vs datable:column vs dt:As name("column")Either index the column by numer column(dt, 1) or prompt the user to select a column or enter a column name. Look into New Window() in the help files.
Column() vs As Column() vs datable:column vs dt:As name("column")JSL has several ways to refer to columns. Let's open a data table first.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Bands data.jmp" );
Now we create a table script that has something like this.
dt = current data table();
print(dt:timestamp == Column(dt, "timestamp"));
// 0
print(Column(dt, "timestamp")==As Column(dt, "timestamp"));
//0
In automated scripts (for example, a graph), when a user changes the name of a column, it seems to adapt the script to the new column name. This failed in custom JSL, with something like Index() appearing.
How one would use all of these methods to make a JSL script robust to column name changes?
Regards,
Automation and ScriptingMass CustomizationRe: Column() vs As Column() vs datable:column vs dt:As name("column")Here is the wish 
catch "missing column" error and provide a selection menu
Should be easy to implement now for JSL Editor - as a similar functionality was just introduced with Jmp 17's new Workflow builder:
https://community.jmp.com/t5/JMP-Wish-List/catch-quot-missing-column-quot-error-and-provide-a-selection/idc-p/561663/highlight/true#M2949
Re: Column() vs As Column() vs datable:column vs dt:As name("column") @brady_brady discusses this topic in detail in Better JSL Smoother Migration: How To Fix Your Own Codeâ @10min
edit:
unfortunately, the video got archived.
https://community.jmp.com/t5/contentarchivals/contentarchivedpage/message-uid/537424#U537424
Re: Column() vs As Column() vs datable:column vs dt:As name("column")Amazing that a Dashboard still works after renaming columns
- if it's stored as a Table Script
edit:
ah, no ... it even works if the Dashboard/Application is NOT stored as a Table Script.
Interesting.
edit2 - limitation:
the JSL "Scripts" of the application don't get updated automatically, just the code in the background of the application.

Re: Column() vs As Column() vs datable:column vs dt:As name("column")you mean something like this?
After running the code, the first two entries in the TABLE SCRIPT were automatically changed to the new name *)
Same behavior for any graph etc. : everything gets automatically adjusted to the new column name.
so cool!
But for As column() and Column() it didn't work.
Neither did it for any column name in a script that is NOT stored as a table script ...
Re: Column() vs As Column() vs datable:column vs dt:As name("column")Because your column names are numbers, this will not happen if you use pure English letters.