Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
adel922
Level I

User Entered Values to Column values using JSL

I am new to JSL Scripting.

I am trying to populate a column using entries from a panel box.

In part of my code below, I am trying to get the value entered ,34, to populate a column named Price Code. However, when I run this code an empty column is returned.

I have tried using Get Values (Num) in place of Set Values(Num) and I still get an empty Price Code column.

 

dataTable = New Table( "Data Table",
Add Rows( 3 ),
New Column( "Customer Name",
Character,
"Nominal",
Set Values( {"Jane", "Scott", "Abby"} )
),
New Column( "Dollar Amount",
"Continuous",
Set Values( [2002, 1323, 1954] )
)
);

popUp = New Window ("Number", << modal(),
        Panel Box("Enter a Number", lineup box ( N col (1)),
            number = Number edit box (34), ),
        Panel Box ("Actions", H List Box (  Button Box ("OK", keep_going = 1;                    
                    Num = :number << Get;),
           Button Box ("Cancel", keep_going = 0)   ),   ),
);

dataTable << New Column("Price Code",Numeric, "Continuous", Set Values(Num));

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: User Entered Values to Column values using JSL

This is a simple 2 issue problem.  

1.  When you referenced

Num = :number << Get;

You are scoping the variable number wrong, ":" in front of the variable, tells JSL to look for a column named "Number" in a data table.  If you either leave it blank, or specify "::" it will look for a memory variable.

2.  If you want the scaler value from the memory variable "NUM" to be populated in all rows of the table you need to specify:

dataTable << New Column( "Price Code", Numeric, "Continuous", Set each Value( Num ) );

So the complete script would be:

Names Default To Here( 1 );
dataTable = New Table( "Data Table",
	Add Rows( 3 ),
	New Column( "Customer Name", Character, "Nominal", Set Values( {"Jane", "Scott", "Abby"} ) ),
	New Column( "Dollar Amount", "Continuous", Set Values( [2002, 1323, 1954] ) )
);

popUp = New Window( "Number",
	<<modal(),
	Panel Box( "Enter a Number", Lineup Box( N Col( 1 ) ), number = Number Edit Box( 34 ) ),
	Panel Box( "Actions",
		H List Box(
			Button Box( "OK",
				keep_going = 1;
				Num = number << Get;
			),
			Button Box( "Cancel", keep_going = 0 )
		), 

	), 

);

dataTable << New Column( "Price Code", Numeric, "Continuous", Set each Value( Num ) );

 

Jim

View solution in original post

17 REPLIES 17
Highlighted
txnelson
Super User

Re: User Entered Values to Column values using JSL

This is a simple 2 issue problem.  

1.  When you referenced

Num = :number << Get;

You are scoping the variable number wrong, ":" in front of the variable, tells JSL to look for a column named "Number" in a data table.  If you either leave it blank, or specify "::" it will look for a memory variable.

2.  If you want the scaler value from the memory variable "NUM" to be populated in all rows of the table you need to specify:

dataTable << New Column( "Price Code", Numeric, "Continuous", Set each Value( Num ) );

So the complete script would be:

Names Default To Here( 1 );
dataTable = New Table( "Data Table",
	Add Rows( 3 ),
	New Column( "Customer Name", Character, "Nominal", Set Values( {"Jane", "Scott", "Abby"} ) ),
	New Column( "Dollar Amount", "Continuous", Set Values( [2002, 1323, 1954] ) )
);

popUp = New Window( "Number",
	<<modal(),
	Panel Box( "Enter a Number", Lineup Box( N Col( 1 ) ), number = Number Edit Box( 34 ) ),
	Panel Box( "Actions",
		H List Box(
			Button Box( "OK",
				keep_going = 1;
				Num = number << Get;
			),
			Button Box( "Cancel", keep_going = 0 )
		), 

	), 

);

dataTable << New Column( "Price Code", Numeric, "Continuous", Set each Value( Num ) );

 

Jim

View solution in original post

Highlighted
adel922
Level I

Re: User Entered Values to Column values using JSL

Thank you so much txnelson

Highlighted
adel922
Level I

Re: User Entered Values to Column values using JSL

Thank you so much txnelson.

Highlighted
shah47
Level II

Re: User Entered Values to Column values using JSL

I was wondering in regards to this solution, how would I go about getting the input from the user in regards to sample name and set that as my sample number? 

 

dt << New Column("Sample Number",Character,Formula(Left(:Sample, Length(:Sample) - 1)),EvalFormula);


InputWindow = New Window( "Enter Input", <<modal(),
V List Box(Align(center),
Panel Box( "Enter Sample Name for Sample 01", Lineup Box( N Col( 1 ) ), number = Text Edit Box( "Enter Sample Name" )),
Panel Box( "Enter Sample Name for Sample 02", Lineup Box( N Col( 1 ) ), number = Text Edit Box( "Enter Sample Name" )),
Panel Box( "Enter Sample Name for Sample 03", Lineup Box( N Col( 1 ) ), number = Text Edit Box( "Enter Sample Name" )),
Panel Box( "Enter Sample Name for Sample 04", Lineup Box( N Col( 1 ) ), number = Text Edit Box( "Enter Sample Name" )),
Panel Box( "Enter Sample Name for Sample 05", Lineup Box( N Col( 1 ) ), number = Text Edit Box( "Enter Sample Name" )),
Panel Box( "Enter Sample Name for Sample 06", Lineup Box( N Col( 1 ) ), number = Text Edit Box( 
Panel Box( "Actions",
H List Box(
Button Box( "OK", keep_going = 1; 
text = :text << Get;),

),
Button Box( "Cancel", keep_going = 0 )
),

),

);

// Sort the samples by sample name
Sample Number<<set property(value ordering, {"01","02","03","04","05","06"});
dt << Sort(By(Sample Number),Order(Ascending),Replace Table);
Highlighted

Re: User Entered Values to Column values using JSL

I think you could make a cleaner and simpler UI with a Table Box() organizing a String Col Box() for the labels and a V List() of Text Edit Box() for the input values.

Learn it once, use it forever!
Highlighted
shah47
Level II

Re: User Entered Values to Column values using JSL

Something like this? But how would you replace the sample number with the user input for sample name?

 

// Create a new column for sample names
dt << New Column("Sample Number",Character,Formula(Left(:Sample, Length(:Sample) - 1)),EvalFormula);
dt = current data table();

InputWindow = New Window( "Enter Input", <<modal(),
Table Box(
		String Col Box( "Sample Number",
			{"Sample 01", "Sample 02", "Sample 03", "Sample 04", "Sample 05", "Sample 06"}
		),
		Col Box(
			"Sample Names",
			Text Edit Box( "Enter Sample Name"),
			Text Edit Box( "Enter Sample Name"),
			Text Edit Box( "Enter Sample Name"),
			Text Edit Box( "Enter Sample Name"),
			Text Edit Box( "Enter Sample Name"),
			Text Edit Box( "Enter Sample Name"),
			
		)));
	




// Sort the samples by sample name
Sample Number<<set property(value ordering, {"01","02","03","04","05","06"});
dt << Sort(By(Sample Number),Order(Ascending),Replace Table);
Highlighted

Re: User Entered Values to Column values using JSL

Here is one way:

 

Names Default To Here( 1 );

InputWindow = New Window( "Enter Input",
	<<modal(),
	Table Box(
		String Col Box( "Sample Number",
			{"Sample 01", "Sample 02", "Sample 03", "Sample 04", "Sample 05",
			"Sample 06"}
		),
		Col Box(
			"Sample Names",
			teb1 = Text Edit Box( "Enter Sample Name" ),
			teb2 = Text Edit Box( "Enter Sample Name" ),
			teb3 = Text Edit Box( "Enter Sample Name" ),
			teb4 = Text Edit Box( "Enter Sample Name" ),
			teb5 = Text Edit Box( "Enter Sample Name" ),
			teb6 = Text Edit Box( "Enter Sample Name" )			
		)
	),
	Button Box( "OK",
		sample name 1 = teb1 << Get Text;
		sample name 2 = teb2 << Get Text;
		sample name 3 = teb3 << Get Text;
		sample name 4 = teb4 << Get Text;
		sample name 5 = teb5 << Get Text;
		sample name 6 = teb6 << Get Text;
	)
);

Show(
	sample name 1,
	sample name 2,
	sample name 3,
	sample name 4,
	sample name 5,
	sample name 6,
);
Learn it once, use it forever!
Highlighted
shah47
Level II

Re: User Entered Values to Column values using JSL

Thank you for the help but I'm getting an error, where am I going wrong?

dt << New Column("Sample Number",Character,Formula(Left(:Sample, Length(:Sample) - 1)),EvalFormula);
dt = current data table();

Names Default To Here( 1 );

InputWindow = New Window( "Enter Input",
	<<modal(),
	Table Box(
		String Col Box( "Sample Number",
			{"Sample 01", "Sample 02", "Sample 03", "Sample 04", "Sample 05",
			"Sample 06"}
		),
		Col Box(
			"Sample Names",
			teb1 = Text Edit Box( "Enter Sample Name" ),
			teb2 = Text Edit Box( "Enter Sample Name" ),
			teb3 = Text Edit Box( "Enter Sample Name" ),
			teb4 = Text Edit Box( "Enter Sample Name" ),
			teb5 = Text Edit Box( "Enter Sample Name" ),
			teb6 = Text Edit Box( "Enter Sample Name" )			
		)
	),
	Button Box( "OK",
		sample name 1 = teb1 << Get Text;
		sample name 2 = teb2 << Get Text;
		sample name 3 = teb3 << Get Text;
		sample name 4 = teb4 << Get Text;
		sample name 5 = teb5 << Get Text;
		sample name 6 = teb6 << Get Text;
	)
);

Show(
	sample name 1,
	sample name 2,
	sample name 3,
	sample name 4,
	sample name 5,
	sample name 6,
);

dt = current data table();
// Sort the samples by sample name
Sample Number<<set property(value ordering, {teb1, teb2, teb3, teb4, teb5, teb6});
dt << Sort(By(Sample Number),Order(Ascending),Replace Table);
Highlighted
txnelson
Super User

Re: User Entered Values to Column values using JSL

What is error message in the log?
Jim
Article Labels

    There are no labels assigned to this post.