cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

JSL rename columns based on user selection

shasha_2
Level III

I am trying to rename column names based on user selection of file. But, I am having trouble renaming the columns. I have added my code, the set name doesn't work for renaming. I think I am doing something wrong. Can anyone please let me know about this?

Clear Log();
dt1_dir = Pick Directory( "Select directory for data table 1" );
dt1_Name = Pick File( "Select data file 1", dt1_dir, {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 0, 0 );
Show( dt1_Name ); 
dt = Open( dt1_Name ); 
Show( dt ); 

dt<< bring window to front;
box = column dialog(
a=collist("BDATE", MAX col(1), min col(1),DataType ("Numeric")),
b=collist("SHIPDATE", MAX col(1), min col(1), DataType ("Numeric")),
c=collist("BUY Date", MAX col(1),min col(1), DataType ("Numeric")), 
);

box["a"] << set name("build date")
box["b"] << set name("shipping date")
box["c"] << set name("buy date")
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User


Re: JSL rename columns based on user selection

box["a"]

returns a JMP List,

{:NPN1}

not a string or an expression.  Therefore you need to properly extract the element from the list, and present it back to JSL as a column

as column((box["a"])[1]) << Set Name( :build date" );

Here are the modification you need to make to make the name changes

as column((box["a"])[1]) << set name( "build date" );
as column((box["b"])[1]) << set name( "shipping date" );
as column((box["c"])[1]) << set name( "buy date" );
Jim

View solution in original post

SDF1
Super User


Re: JSL rename columns based on user selection

Hi @shasha_2 ,

 

  I'm not 100% sure of what you want to do and how you intend to use the Column Dialog() command, but the script below will do what you want. It also gives you a lot more flexibility in terms of what options you have in your new window, etc. If you want to make the window modal, just add <<Modal here: New Window("Select Columns", <<Modal,  -- and then continue on.

Names Default To Here( 1 );

bwidth = 100;

dt = New Table("test",
	Add Rows(3),
	New Column("Col 1", Continuous),
	New Column("Col 2", Continuous),
	New Column("Col 3", Continuous)
);

dt << bring window to front;
box_win = New Window( "Select Columns",
	H List Box(
		Panel Box( "Select Columns", ColListData = Col List Box( dt, All, Grouped, width( bwidth ), nLines( 5 ) ) ),
		V List Box(
			Panel Box( "Case Selected Columns Into Roles",
				Lineup Box( N Col( 2 ), Spacing( 3 ),
					Button Box( "BDATE", colLista << Append( ColListData << Get Selected ) ),
					ColLista = Col List Box( width( bwidth ), N Lines( 1 ), Max Items( 1 ), Min Items( 1 ), <<Set Data Type( "Numeric" ) ),
					Button Box( "SHIPDATE", colListb << Append( ColListData << Get Selected ) ),
					ColListb = Col List Box( width( bwidth ), N Lines( 1 ), Max Items( 1 ), Min Items( 1 ), <<Set Data Type( "Numeric" ) ),
					Button Box( "BUY Date", colListc << Append( ColListData << Get Selected ) ),
					ColListc = Col List Box( width( bwidth ), N Lines( 1 ), Max Items( 1 ), Min Items( 1 ), <<Set Data Type( "Numeric" ) ),
					Button Box( "Remove",
						ColLista << RemoveSelected;
						ColListb << RemoveSelected;
						ColListc << RemoveSelected;
					),
					Spacer Box()
				)
			),
			Lineup Box( N Col( 3 ), Spacing( 0, 3 ),
				Spacer Box( <<Set Auto Stretching( 1, 0 ) ),
				Button Box( "OK",
					acol = ColLista << Get Items;
					As Column( acol ) << Set Name( "build date" );
					bcol = ColListb << Get Items;
					As Column( bcol ) << set name( "shipping date" );
					ccol = ColListc << Get Items;
					As Column( ccol ) << set name( "buy date" );
					box_win << Close Window;
				),
				Button Box( "Cancel", box_win << Close Window )
			)
		)

	)
);

Hope this helps,

DS

View solution in original post

2 REPLIES 2
txnelson
Super User


Re: JSL rename columns based on user selection

box["a"]

returns a JMP List,

{:NPN1}

not a string or an expression.  Therefore you need to properly extract the element from the list, and present it back to JSL as a column

as column((box["a"])[1]) << Set Name( :build date" );

Here are the modification you need to make to make the name changes

as column((box["a"])[1]) << set name( "build date" );
as column((box["b"])[1]) << set name( "shipping date" );
as column((box["c"])[1]) << set name( "buy date" );
Jim
SDF1
Super User


Re: JSL rename columns based on user selection

Hi @shasha_2 ,

 

  I'm not 100% sure of what you want to do and how you intend to use the Column Dialog() command, but the script below will do what you want. It also gives you a lot more flexibility in terms of what options you have in your new window, etc. If you want to make the window modal, just add <<Modal here: New Window("Select Columns", <<Modal,  -- and then continue on.

Names Default To Here( 1 );

bwidth = 100;

dt = New Table("test",
	Add Rows(3),
	New Column("Col 1", Continuous),
	New Column("Col 2", Continuous),
	New Column("Col 3", Continuous)
);

dt << bring window to front;
box_win = New Window( "Select Columns",
	H List Box(
		Panel Box( "Select Columns", ColListData = Col List Box( dt, All, Grouped, width( bwidth ), nLines( 5 ) ) ),
		V List Box(
			Panel Box( "Case Selected Columns Into Roles",
				Lineup Box( N Col( 2 ), Spacing( 3 ),
					Button Box( "BDATE", colLista << Append( ColListData << Get Selected ) ),
					ColLista = Col List Box( width( bwidth ), N Lines( 1 ), Max Items( 1 ), Min Items( 1 ), <<Set Data Type( "Numeric" ) ),
					Button Box( "SHIPDATE", colListb << Append( ColListData << Get Selected ) ),
					ColListb = Col List Box( width( bwidth ), N Lines( 1 ), Max Items( 1 ), Min Items( 1 ), <<Set Data Type( "Numeric" ) ),
					Button Box( "BUY Date", colListc << Append( ColListData << Get Selected ) ),
					ColListc = Col List Box( width( bwidth ), N Lines( 1 ), Max Items( 1 ), Min Items( 1 ), <<Set Data Type( "Numeric" ) ),
					Button Box( "Remove",
						ColLista << RemoveSelected;
						ColListb << RemoveSelected;
						ColListc << RemoveSelected;
					),
					Spacer Box()
				)
			),
			Lineup Box( N Col( 3 ), Spacing( 0, 3 ),
				Spacer Box( <<Set Auto Stretching( 1, 0 ) ),
				Button Box( "OK",
					acol = ColLista << Get Items;
					As Column( acol ) << Set Name( "build date" );
					bcol = ColListb << Get Items;
					As Column( bcol ) << set name( "shipping date" );
					ccol = ColListc << Get Items;
					As Column( ccol ) << set name( "buy date" );
					box_win << Close Window;
				),
				Button Box( "Cancel", box_win << Close Window )
			)
		)

	)
);

Hope this helps,

DS