cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ressel
Level VI

Part of JSL code not working in final script, but working if isolated

Warning: Beginner level question

 

I have a data table to which I am adding a temporary column (:Parameter_new) to fill up with entries if a certain condition is met. The entries I then want to get into another column (:Parameter_old). My impression is that the code behaves differently when it is part of the final script, compared to when I copy individual lines into a different script. When applying the script code line by line, everything works as expected. When implemented into the final script I only get blank values. Where am I going wrong?

//Code works OK
  dt << New Column ("Parameter_new", character);										
  dt << go to( :Parameter_new ) << move selected columns( After( :Parameter_old ));				

  For Each Row(
	  If(:Parameter_old == "Parameter x",
		 :Parameter_new = :Parameter_old || " " || "by" || " " ||:Method_description));			

  dt << select where(:Parameter_old == "Parameter x");

//Code does not work and deletes all entries in column "Parameter_old", i.e. cells come out blank
//Code does however work if applied individually, line by line
  :Name("Parameter_old")[dt << get selected rows] = :Parameter_new;
1 ACCEPTED SOLUTION

Accepted Solutions
Ressel
Level VI

Re: Part of JSL code not working in final script, but working if isolated

Do I feel stupid learning about Ifs now...

 

Also, why is my JSL code snippet all grey? How can I get the correct font & colours?

 

dt2 << New Column ("Parameter_new", character);
dt2 << go to( :Parameter_new ) << move selected columns( After( :Parameter_old ));
		
For Each Row(
	If(	:Parameter_old == "Parameter x", :Parameter_new = :Parameter_old || " " || "by" || " " || :Method_description,
		:Parameter_old != "Parameter x", :Parameter = :Parameter_old));

View solution in original post

8 REPLIES 8
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Part of JSL code not working in final script, but working if isolated

JMP probably is not evaluating the formula in Parameter_new before moving to the next line.  Try adding this after your For Each Row function:

 

dt << Run Formulas;

Also, you could use a wait:

Wait(0);
Ressel
Level VI

Re: Part of JSL code not working in final script, but working if isolated

Thanks ih, I appreciate the response! Tried both, didn't work. Open to suggestions while fishing in the Scripting Guide.

Craige_Hales
Super User

Re: Part of JSL code not working in final script, but working if isolated

The final statement has a matrix on the left-hand-side (LHS) and a column on the right-hand-side (RHS).

 

You have two different cases: inside the ForEachRow, and outside. If inside, there is an implicit row and the column resolves to a scalar. If outside, there is not an implicit row. You probably had exactly one row selected when it worked inside the ForEachRow.

 

a column matrix (LHS) only supports a scalar on the RHS. It won't work right with a matrix on the RHS.

 

You can use Data table subscripting  instead. That treats the table as a 2D matrix (3 rows, 1 col in this tiny example.)

 

dt = Open( "$sample_data/big class.jmp" );
dt[[2, 3, 4], {name}] = dt[[5, 6, 7], {name}];
Craige
Ressel
Level VI

Re: Part of JSL code not working in final script, but working if isolated

Thanks. Looks interesting. Please give me some time before I have sorted out the details around this approach, can post my initial code in complete form and accept your post as solution.

 

(Also, why is my JSL code formatted without colour in my posting? I am using the <JSL> icon for inserting snippets.)

 

Edit: Wonderful post about subscripting. Wasn't aware of that, but made for some interesting reading. I have since accepted a response from myself as solution, since it appeared intuitively easier to me.

Ressel
Level VI

Re: Part of JSL code not working in final script, but working if isolated

Do I feel stupid learning about Ifs now...

 

Also, why is my JSL code snippet all grey? How can I get the correct font & colours?

 

dt2 << New Column ("Parameter_new", character);
dt2 << go to( :Parameter_new ) << move selected columns( After( :Parameter_old ));
		
For Each Row(
	If(	:Parameter_old == "Parameter x", :Parameter_new = :Parameter_old || " " || "by" || " " || :Method_description,
		:Parameter_old != "Parameter x", :Parameter = :Parameter_old));
Jeff_Perkinson
Community Manager Community Manager

Re: Part of JSL code not working in final script, but working if isolated

I'm glad you were able to resolve the issue. As for the color coding, it looks like you're using the </> that's to the left of the <JSL> in the editor toolbar. 

 

You might have tried to use them both on the same snippet but only one works. I've fixed the formatting in both your posts.

-Jeff
ErraticAttack
Level VI

Re: Part of JSL code not working in final script, but working if isolated

All of my <JSL> code blocks get flagged for errors when posting here to the Community forums.  Specifically, the `class=" language-jsl"` inside the <code> block gets removed, as below

Names Default To Here( 1 );
x = [10, 50, 90];
y = [10, 90, 10];
New Window( "Line Seg Example", g = Graph Box( Line Seg( x, y ) ) );
frame = g[FrameBox( 1 )];
seg = (frame << Find Seg( Line Seg( 1 ) ));

ErraticAttach_0-1637024605324.png

 

 

Jordan
Ryan_Gilmore
Community Manager Community Manager

Re: Part of JSL code not working in final script, but working if isolated

Hi. There appears to have been a change in the Community platform. We have contacted support. In the meantime, we have implemented a temporary fix which should allow you to use the <JSL> button as expected. Thanks.