cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar

How do I get to prompt a user to define the LSL and USL for each subset table?

A customer asked how to create a JSL script to prompt other users to define the LSL and USL for each subset table.

 

I figured might as well post the script here to help others who might have the same request in the future. Anyone who has feedback, questions or enhancements, please feel free to add a comment.

 


// Subset data table

// → Data Table( "Product=B" )

dtList = Open("$SAMPLE_DATA/Abrasion.jmp")
<<Subset(
	By(:Shift), 
	All rows, 
	Selected columns only(0)
);

Show(dtList);

For(i = 1, i <= N Items(dtList), i++, 
	dt = dtList[i];
// Run the script
	Print(dtList[i]);
	Wait(1);
	ex = New Window("Defining Specification Limits", 
		<<Type("Modal Dialog"), 
		<<Return Result, 
		<<On Validate(
			LSL_value = LSL_var << Get;
			USL_value = USL_var << Get;
			If(LSL_value < USL_value, // in range
				USL_var << Background Color("Background"); // this field does not need attention
				1; //the number is good, validate
			, // else out of range
				USL_var << Background Color("Light Yellow");
				LSL_var << Background Color("Light Yellow"); // this field needs attention
				0; // the number is bad, do not validate
			) // the result of this if(...) is the OnValidate( ) answer, 0 or 1
		), 
		Border Box(top(20), bottom(20), Left(20), Right(20), 
			V List Box(
				Text Box("Enter a value for the LSL and USL in " || Char(dtList[i])), 
				H List Box(
					V List Box(Text Box("LSL "), Text Box("USL ")),
					V List Box(LSL_var = Number Edit Box(0), USL_var = Number Edit Box(1))
				), 
				H List Box(Button Box("OK"), Button Box("Cancel"))
			)
		)
	);

//  the Modal window must be closed before the following code runs
	If(
		ex["button"] == 1 // not canceled
	, // then show the value
		Write(LSL_value);
		Write(USL_value);
		Print(LSL_value, USL_value)
		;
	, 
		Write("CANCEL"); // cancel button or red X was pressed
	);
	
	Wait(0.2);
	
	Eval(
		Eval Expr(
			dt:Abrasion << Set Property(
				"Spec Limits", 
				{LSL(Expr(LSL_value)), USL(Expr(USL_value)), Show Limits(0)}
			);
		)
	);
	Wait(1);
);
1 REPLY 1
jthi
Super User

Re: How do I get to prompt a user to define the LSL and USL for each subset table?

Great script! To make it more generic you possibly would have to answer some extra questions:

  • would you always use this on all tables which are open or should the user be able to pick the tables?
  • how is the column defined which the specification limits will be set to? First column in table? Should user be able to pick them or maybe just let user set them to all continuous columns?

I would also start the script with Names Default To Here(1); to avoid some issues global namespace might cause.

 

You could also possibly "make" the customers utilize JMP's Manage Limits. "Issue" with this is that user would have to know to press Save to Column Properties and then press OK

 

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Abrasion.jmp");
dt <<Subset(
	By(:Shift), 
	All rows, 
	Selected columns only(0)
);
Close(dt, no save);


For Each({dt_ref}, Get Data Table List(),
	nw = New Window("Manage Limits for " || (dt_ref << get name) || " - :Abrasion" , << modal, dt_ref << Manage Limits(Process Variables(:Abrasion)));
);

And for "generic" version which would just take all tables

 

 

Names Default To Here(1);

For Each({dt_ref}, Get Data Table List(),
	New Window("Manage Limits for " || (dt_ref << get name) || " - :Abrasion" , << modal, dt_ref << Manage Limits(Process Variables(dt_ref << Get Column Names("Continuous"))));
);

 

I would most likely at least provide users the option to pick which tables to use so it would be something like this when using manage limits

 

 

Names Default To Here(1);

dtlist = Get Data Table List();

dtnames = Transform Each({dtref}, dtlist,
	dtref << get name
);

// I don't like using modal windows, but maybe it is fine in this case
nw = New Window("Pick tables to set spec limits to", << modal, << return result,
	<< On Validate(
		If(N Items(lb_tables << get selected) < 1,
			New Window("Warning", << modal, 
				H List Box(align("center"),
					Icon box("Warning"),
					Text Box("Select at least one table or cancel"), << Set Window Icon("Warning")
				)
			);
			0;
		,
			1;
		);
	),
	Lineup Box(N Col(2),
		Panel Box("Pick Tables",
			lb_tables = Listbox(dtnames)
		),
		Panel Box("Actions",
			Button Box("OK",
				user_selections = lb_tables << get selected;
			),
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] == 1, 
	For Each({tablename}, nw["lb_tables"],
		dt_ref = Datatable(tablename);
		New Window("Manage Limits for " || (dt_ref << get name) || " - :Abrasion" , << modal, 
			H List Box(align("bottom"),
				ml = dt_ref << Manage Limits(Process Variables(dt_ref << Get Column Names("Continuous"))),
				Lineup Box(N Col(1),
					Button Box("OK",
						ml << Save to Column Properties; // could be used to "force save"
					),
					Button Box("Cancel")
				)
			)
		);
	);
);

 

-Jarmo

Recommended Articles