<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Session 9: Advanced JSL in JMP Scripters Club Discussions</title>
    <link>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680667#M108</link>
    <description>&lt;P&gt;And here are few of the very common problems you might come across and how you can solve them with expressions and by evaluating them when needed.&lt;/P&gt;
&lt;H2&gt;1. Using constant in a formula&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;Your formula works only once and looks like this after save and re-open:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1695402326844.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56940iC838F7E28E031317/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1695402326844.png" alt="jthi_0-1695402326844.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; . Most of the time I use Eval(EvalExpr()).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

value_to_add = 5;

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("HeightAddFive", Numeric, Continuous, Formula(
		Expr(value_to_add) + :height
	));	
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H2&gt;2. Using a constants in graphic script&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;You end up with a script like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Graph Builder(
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
	SendToReport(
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Add Graphics Script(
				7,
				Description(""),
				Pen Color(color_to_use);
				Pen Size(size_to_use);
				H Line(value_to_add);
			)}
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use Eval(EvalExpr()) (or Substitute() is other good option)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

value_to_add = 80;

gb = dt &amp;lt;&amp;lt; Run Script("Graph Builder Smoother Line");
color_to_use = "Red";
size_to_use = 2;

Eval(EvalExpr(
	Report(gb)[FrameBox(1)] &amp;lt;&amp;lt; Add Graphics Script(
		Pen Color(Expr(color_to_use));
		Pen Size(Expr(size_to_use));
		H Line(Expr(value_to_add));
	);	
));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H2&gt;3. Setting variables as spec limits&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;Spec limits are not being set correctly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;Start by letting JMP create code (add column property and take the code from Enhanced Log or right click on the column and "Copy Column Properties". You get something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Data Table("Big Class"):height &amp;lt;&amp;lt; Set Property(
	"Spec Limits",
	{LSL(11), USL(22), Target(12), Show Limits(1)}
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Improve this script to use variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
aa_specs = Associative Array();
aa_specs["height"] = ["LSL" =&amp;gt; 50, "USL" =&amp;gt; 80];
aa_specs["weight"] = ["LSL" =&amp;gt; 60, "USL" =&amp;gt; 160];

For Each({col_name}, dt &amp;lt;&amp;lt; Get Column Names("String"),
	If(Contains(aa_specs, col_name),
		Eval(EvalExpr(
			Column(dt, col_name) &amp;lt;&amp;lt; Set Property("Spec Limits" ,{
				LSL(Expr(aa_specs[col_name]["LSL"])), 
				USL(Expr(aa_specs[col_name]["USL"])),
				Target(Expr((aa_specs[col_name]["LSL"] + aa_specs[col_name]["USL"])/2)),
				Show Limits(1)
			})
		));
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;4. Adding table scripts to table&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;You end up with table script which says something like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1695403301656.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56942iC4DF7F11E62C0FDB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1695403301656.png" alt="jthi_1-1695403301656.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;Eval(EvalExpr()) with Name Expr(). This won't create the graph at all. If you want to run it use &amp;lt;&amp;lt; Run Script("My nice graph") or evalute the expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb_expr = Expr(dt &amp;lt;&amp;lt; Graph Builder(
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
));

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Script("My nice graph", Expr(Name Expr(gb_expr)));
));

// dt &amp;lt;&amp;lt; Run Script("My nice graph");
// Eval(gb_expr);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;but in cases like this I would most of the time use &amp;lt;&amp;lt; Save Script to Data Table, but this will run the platform so remember to close it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb_expr = Expr(dt &amp;lt;&amp;lt; Graph Builder(
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
));

gb = Eval(gb_expr);
gb &amp;lt;&amp;lt; Save Script to Data Table("My nice graph");
gb &amp;lt;&amp;lt; Close Window;
Wait(0);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;5. Build formulas based on user selections from Col List Boxes&lt;/H2&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("Selections",
	clb_x = Col List Box(dt, &amp;lt;&amp;lt; Set items({"height"})),
	clb_y = Col List Box(dt, &amp;lt;&amp;lt; Set items({"weight"}))
);

x_selection = clb_x &amp;lt;&amp;lt; get items;
y_selection = clb_y &amp;lt;&amp;lt; get items; // these are strings

wait(2);
nw &amp;lt;&amp;lt; Close Window;

// Using Eval(EvalExpr())
Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("Multiplication_EvalExpr", Numeric, Continuous, Formula(
		Expr(NameExpr(AsColumn(dt, x_selection))) * Expr(NameExpr(AsColumn(dt, y_selection)))
	));
));

// Using Eval(Substitute())
Eval(Substitute(
	Expr(dt &amp;lt;&amp;lt; New Column("Multiplication_EvalSubstitute", Numeric, Continuous, Formula(_xcol_ * _ycol_))),
	Expr(_xcol_), Name Expr(AsColumn(dt, x_selection)),
	Expr(_ycol_), Name Expr(AsColumn(dt, y_selection))
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;6. Use expressions to build user-interfaces (not the best example)&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;Code gets clunky&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

nw = New Window("asdas",
	Button Box("Perform Action1",
		Caption("Perform Action1")
	),
	Button Box("Perform Action2",
		Caption("Perform Action2")
	),
	Button Box("Perform Action3",
		Caption("Perform Action3")
	)	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Problem2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code doesn't work (might happen as window doesn't always know about all variables)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

caption_expr = Expr(
	Caption("Perform Action");
);

nw = New Window("asdas",
	Button Box("Perform Action1",
		caption_expr
	),
	Button Box("Perform Action2",
		caption_expr
	),
	Button Box("Perform Action3",
		caption_expr
	)	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1695404209373.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56943iA044985BEB29C425/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1695404209373.png" alt="jthi_2-1695404209373.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution1:&lt;/P&gt;
&lt;P&gt;Evaluate the expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

caption_expr = Expr(
	Caption("Perform Action");
);

Eval(EvalExpr(
	nw = New Window("asdas",
		Button Box("Perform Action1",
			Expr(Name Expr(caption_expr))
		),
		Button Box("Perform Action2",
			Expr(Name Expr(caption_expr))
		),
		Button Box("Perform Action3",
			Expr(Name Expr(caption_expr))
		)	
	);
))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case you could also use &amp;lt;&amp;lt; Set Function(Function([}))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

nw = New Window("asdas",
	Button Box("Perform Action1", &amp;lt;&amp;lt; Set Function(function({this},
		Caption(this &amp;lt;&amp;lt; get button name);
	))),
	Button Box("Perform Action2", &amp;lt;&amp;lt; Set Function(function({this},
		Caption(this &amp;lt;&amp;lt; get button name);
	))),
	Button Box("Perform Action3", &amp;lt;&amp;lt; Set Function(function({this},
		Caption(this &amp;lt;&amp;lt; get button name);
	)))
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

button_caption_expr = Expr(
	Caption(this &amp;lt;&amp;lt; get button name);
);

Eval(EvalExpr(
	nw = New Window("asdas",
		Button Box("Perform Action1", &amp;lt;&amp;lt; Set Function(function({this},
			Expr(NameExpr(button_caption_expr));
		))),
		Button Box("Perform Action2", &amp;lt;&amp;lt; Set Function(function({this},
			Expr(NameExpr(button_caption_expr));
		))),
		Button Box("Perform Action3", &amp;lt;&amp;lt; Set Function(function({this},
			Expr(NameExpr(button_caption_expr));
		)))
	);
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution 4:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use function (solution3 might be more robust)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

show_btn_caption = function({btn_ref}, {Default Local},
	Caption(btn_ref &amp;lt;&amp;lt; get button name);
);

nw = New Window("asdas",
	Button Box("Perform Action1", &amp;lt;&amp;lt; Set Function(function({this},
		show_btn_caption(this);
	))),
	Button Box("Perform Action2", &amp;lt;&amp;lt; Set Function(function({this},
		show_btn_caption(this);
	))),
	Button Box("Perform Action3", &amp;lt;&amp;lt; Set Function(function({this},
		show_btn_caption(this);
	)))
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution5:&lt;/P&gt;
&lt;P&gt;Use function to build the buttons&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

create_btn = function({btn_title}, {Default Local},
	btn = Button Box(btn_title, &amp;lt;&amp;lt; Set Function(function({this},
		Caption(btn_ref &amp;lt;&amp;lt; get button name);
	)));
	
	return(btn);
);

nw = New Window("asdas",
	create_btn("Perform Action1"),
	create_btn("Perform Action2"),
	create_btn("Perform Action3")
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2023 17:47:27 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-09-22T17:47:27Z</dc:date>
    <item>
      <title>Session 9: Advanced JSL</title>
      <link>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680045#M106</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Includes, Functions, expr(), 'eval(evalexpr)', 'eval(parse)'.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Presenters:&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4182"&gt;@maurogerber&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Video 1: Introduction&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6337551635112w960h540r911" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6337551635112" data-account="6058004218001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6058004218001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6337551635112w960h540r911');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.jmp.com/t5/video/gallerypage/video-id/6337551635112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Video 2: Example&lt;/P&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6337552705112w1280h720r704" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6337552705112" data-account="6058004218001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6058004218001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6337552705112w1280h720r704');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.jmp.com/t5/video/gallerypage/video-id/6337552705112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 12:29:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680045#M106</guid>
      <dc:creator>maria_astals</dc:creator>
      <dc:date>2023-09-21T12:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Session 9: Advanced JSL</title>
      <link>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680090#M107</link>
      <description>&lt;P&gt;Some of the links I did mention to post here&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;One of the best post in community regarding building formulas using expressions
&lt;UL&gt;
&lt;LI&gt;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Deeper knowledge on expressions
&lt;UL&gt;
&lt;LI&gt;&lt;LI-MESSAGE title="Expression Handling Functions: Part I - Unraveling the Expr(), NameExpr(), Eval(), ... Conundrum" uid="28963" url="https://community.jmp.com/t5/JMPer-Cable/Expression-Handling-Functions-Part-I-Unraveling-the-Expr/m-p/28963#U28963" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; (sadly there is no part two). I will also attach the same PDF to this post&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;LI-MESSAGE title="Can you construct this without writing expression as a string?" uid="369323" url="https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369323#U369323" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;LI-MESSAGE title="How to script Column Properties using variables" uid="575399" url="https://community.jmp.com/t5/JMP-Knowledge-Base/How-to-script-Column-Properties-using-variables/m-p/575399#U575399" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;LI-MESSAGE title="How to use a variable value in a formula" uid="575397" url="https://community.jmp.com/t5/JMP-Knowledge-Base/How-to-use-a-variable-value-in-a-formula/m-p/575397#U575397" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 21 Sep 2023 13:16:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680090#M107</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-21T13:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Session 9: Advanced JSL</title>
      <link>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680667#M108</link>
      <description>&lt;P&gt;And here are few of the very common problems you might come across and how you can solve them with expressions and by evaluating them when needed.&lt;/P&gt;
&lt;H2&gt;1. Using constant in a formula&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;Your formula works only once and looks like this after save and re-open:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1695402326844.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56940iC838F7E28E031317/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1695402326844.png" alt="jthi_0-1695402326844.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; . Most of the time I use Eval(EvalExpr()).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

value_to_add = 5;

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("HeightAddFive", Numeric, Continuous, Formula(
		Expr(value_to_add) + :height
	));	
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H2&gt;2. Using a constants in graphic script&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;You end up with a script like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Graph Builder(
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
	SendToReport(
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Add Graphics Script(
				7,
				Description(""),
				Pen Color(color_to_use);
				Pen Size(size_to_use);
				H Line(value_to_add);
			)}
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use Eval(EvalExpr()) (or Substitute() is other good option)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

value_to_add = 80;

gb = dt &amp;lt;&amp;lt; Run Script("Graph Builder Smoother Line");
color_to_use = "Red";
size_to_use = 2;

Eval(EvalExpr(
	Report(gb)[FrameBox(1)] &amp;lt;&amp;lt; Add Graphics Script(
		Pen Color(Expr(color_to_use));
		Pen Size(Expr(size_to_use));
		H Line(Expr(value_to_add));
	);	
));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H2&gt;3. Setting variables as spec limits&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;Spec limits are not being set correctly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;Start by letting JMP create code (add column property and take the code from Enhanced Log or right click on the column and "Copy Column Properties". You get something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Data Table("Big Class"):height &amp;lt;&amp;lt; Set Property(
	"Spec Limits",
	{LSL(11), USL(22), Target(12), Show Limits(1)}
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Improve this script to use variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
aa_specs = Associative Array();
aa_specs["height"] = ["LSL" =&amp;gt; 50, "USL" =&amp;gt; 80];
aa_specs["weight"] = ["LSL" =&amp;gt; 60, "USL" =&amp;gt; 160];

For Each({col_name}, dt &amp;lt;&amp;lt; Get Column Names("String"),
	If(Contains(aa_specs, col_name),
		Eval(EvalExpr(
			Column(dt, col_name) &amp;lt;&amp;lt; Set Property("Spec Limits" ,{
				LSL(Expr(aa_specs[col_name]["LSL"])), 
				USL(Expr(aa_specs[col_name]["USL"])),
				Target(Expr((aa_specs[col_name]["LSL"] + aa_specs[col_name]["USL"])/2)),
				Show Limits(1)
			})
		));
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;4. Adding table scripts to table&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;You end up with table script which says something like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1695403301656.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56942iC4DF7F11E62C0FDB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1695403301656.png" alt="jthi_1-1695403301656.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;P&gt;Eval(EvalExpr()) with Name Expr(). This won't create the graph at all. If you want to run it use &amp;lt;&amp;lt; Run Script("My nice graph") or evalute the expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb_expr = Expr(dt &amp;lt;&amp;lt; Graph Builder(
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
));

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Script("My nice graph", Expr(Name Expr(gb_expr)));
));

// dt &amp;lt;&amp;lt; Run Script("My nice graph");
// Eval(gb_expr);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;but in cases like this I would most of the time use &amp;lt;&amp;lt; Save Script to Data Table, but this will run the platform so remember to close it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb_expr = Expr(dt &amp;lt;&amp;lt; Graph Builder(
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
));

gb = Eval(gb_expr);
gb &amp;lt;&amp;lt; Save Script to Data Table("My nice graph");
gb &amp;lt;&amp;lt; Close Window;
Wait(0);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;5. Build formulas based on user selections from Col List Boxes&lt;/H2&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("Selections",
	clb_x = Col List Box(dt, &amp;lt;&amp;lt; Set items({"height"})),
	clb_y = Col List Box(dt, &amp;lt;&amp;lt; Set items({"weight"}))
);

x_selection = clb_x &amp;lt;&amp;lt; get items;
y_selection = clb_y &amp;lt;&amp;lt; get items; // these are strings

wait(2);
nw &amp;lt;&amp;lt; Close Window;

// Using Eval(EvalExpr())
Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("Multiplication_EvalExpr", Numeric, Continuous, Formula(
		Expr(NameExpr(AsColumn(dt, x_selection))) * Expr(NameExpr(AsColumn(dt, y_selection)))
	));
));

// Using Eval(Substitute())
Eval(Substitute(
	Expr(dt &amp;lt;&amp;lt; New Column("Multiplication_EvalSubstitute", Numeric, Continuous, Formula(_xcol_ * _ycol_))),
	Expr(_xcol_), Name Expr(AsColumn(dt, x_selection)),
	Expr(_ycol_), Name Expr(AsColumn(dt, y_selection))
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;6. Use expressions to build user-interfaces (not the best example)&lt;/H2&gt;
&lt;P&gt;Problem:&lt;/P&gt;
&lt;P&gt;Code gets clunky&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

nw = New Window("asdas",
	Button Box("Perform Action1",
		Caption("Perform Action1")
	),
	Button Box("Perform Action2",
		Caption("Perform Action2")
	),
	Button Box("Perform Action3",
		Caption("Perform Action3")
	)	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Problem2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code doesn't work (might happen as window doesn't always know about all variables)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

caption_expr = Expr(
	Caption("Perform Action");
);

nw = New Window("asdas",
	Button Box("Perform Action1",
		caption_expr
	),
	Button Box("Perform Action2",
		caption_expr
	),
	Button Box("Perform Action3",
		caption_expr
	)	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1695404209373.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56943iA044985BEB29C425/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1695404209373.png" alt="jthi_2-1695404209373.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution1:&lt;/P&gt;
&lt;P&gt;Evaluate the expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

caption_expr = Expr(
	Caption("Perform Action");
);

Eval(EvalExpr(
	nw = New Window("asdas",
		Button Box("Perform Action1",
			Expr(Name Expr(caption_expr))
		),
		Button Box("Perform Action2",
			Expr(Name Expr(caption_expr))
		),
		Button Box("Perform Action3",
			Expr(Name Expr(caption_expr))
		)	
	);
))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case you could also use &amp;lt;&amp;lt; Set Function(Function([}))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

nw = New Window("asdas",
	Button Box("Perform Action1", &amp;lt;&amp;lt; Set Function(function({this},
		Caption(this &amp;lt;&amp;lt; get button name);
	))),
	Button Box("Perform Action2", &amp;lt;&amp;lt; Set Function(function({this},
		Caption(this &amp;lt;&amp;lt; get button name);
	))),
	Button Box("Perform Action3", &amp;lt;&amp;lt; Set Function(function({this},
		Caption(this &amp;lt;&amp;lt; get button name);
	)))
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

button_caption_expr = Expr(
	Caption(this &amp;lt;&amp;lt; get button name);
);

Eval(EvalExpr(
	nw = New Window("asdas",
		Button Box("Perform Action1", &amp;lt;&amp;lt; Set Function(function({this},
			Expr(NameExpr(button_caption_expr));
		))),
		Button Box("Perform Action2", &amp;lt;&amp;lt; Set Function(function({this},
			Expr(NameExpr(button_caption_expr));
		))),
		Button Box("Perform Action3", &amp;lt;&amp;lt; Set Function(function({this},
			Expr(NameExpr(button_caption_expr));
		)))
	);
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution 4:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use function (solution3 might be more robust)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

show_btn_caption = function({btn_ref}, {Default Local},
	Caption(btn_ref &amp;lt;&amp;lt; get button name);
);

nw = New Window("asdas",
	Button Box("Perform Action1", &amp;lt;&amp;lt; Set Function(function({this},
		show_btn_caption(this);
	))),
	Button Box("Perform Action2", &amp;lt;&amp;lt; Set Function(function({this},
		show_btn_caption(this);
	))),
	Button Box("Perform Action3", &amp;lt;&amp;lt; Set Function(function({this},
		show_btn_caption(this);
	)))
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution5:&lt;/P&gt;
&lt;P&gt;Use function to build the buttons&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

create_btn = function({btn_title}, {Default Local},
	btn = Button Box(btn_title, &amp;lt;&amp;lt; Set Function(function({this},
		Caption(btn_ref &amp;lt;&amp;lt; get button name);
	)));
	
	return(btn);
);

nw = New Window("asdas",
	create_btn("Perform Action1"),
	create_btn("Perform Action2"),
	create_btn("Perform Action3")
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 17:47:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Session-9-Advanced-JSL/m-p/680667#M108</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-22T17:47:27Z</dc:date>
    </item>
  </channel>
</rss>

