<?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: How to close the correct tables with &amp;quot;On close&amp;quot; when running the same script multiple times? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724541#M90730</link>
    <description>&lt;P&gt;Names Default To Here(1); at the start of script or maybe using window scope (or box). Scripting Guide has some information regarding namespaces and scopes&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/global-and-local-variables.shtml#" target="_self"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/global-and-local-variables.shtml#&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-scoping-and-namespaces.shtml#" target="_self"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-scoping-and-namespaces.shtml#&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/scoped-names.shtml#" target="_self"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/scoped-names.shtml#&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You can move to different pages from left side menu&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1708101078634.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/61172i488E9E6F24313DA6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1708101078634.png" alt="jthi_0-1708101078634.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;or top right arrows&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1708101086555.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/61173iBFEC91E270D849C5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1708101086555.png" alt="jthi_1-1708101086555.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 16:31:33 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-02-16T16:31:33Z</dc:date>
    <item>
      <title>How to close the correct tables with "On close" when running the same script multiple times?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724292#M90637</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an add-in outputting a graph with several tables hidden in the background.&lt;/P&gt;&lt;P&gt;Upon closing the window I use the "On Close" function to close related data tables, like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt; New window() &amp;lt;&amp;lt; On close(
			Close(TableA, nosave);
			Close(TableB, nosave);
		) ; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is if I run the script twice, TableA of the first run will be overwritten during the second script execution.&lt;/P&gt;&lt;P&gt;I have tried going around the problem by using a Unique ID created at each script launch, like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NewWindow() &amp;lt;&amp;lt; On Close(
	For(i = NItems(GetWindowList() &amp;lt;&amp;lt; Get Window Title()), i &amp;gt; 0, i--,
		win = GetWindow((GetWindowList() &amp;lt;&amp;lt; Get Window Title())[i]);
		If(Contains(win &amp;lt;&amp;lt; get window title, Eval(uniqueID)) != 0,
			win &amp;lt;&amp;lt; closewindow()
		);
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately the same problem remains, UniqueID is overwritten.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to reference the tables correctly so that closing the window will close the correct tables?&lt;/P&gt;&lt;P&gt;Thank you in advance for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 13:36:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724292#M90637</guid>
      <dc:creator>rcookie</dc:creator>
      <dc:date>2024-02-14T13:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to close the correct tables with "On close" when running the same script multiple times?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724299#M90640</link>
      <description>&lt;P&gt;Evaluate the tables to your On Close&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(EvalExpr(
	New Window() &amp;lt;&amp;lt; On close(
		Try(Close(Expr(TableA), nosave));
		Try(Close(Expr(TableB), nosave));
	)
));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Feb 2024 14:17:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724299#M90640</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-02-14T14:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to close the correct tables with "On close" when running the same script multiple times?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724323#M90642</link>
      <description>&lt;P&gt;Amazing, thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 15:26:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724323#M90642</guid>
      <dc:creator>rcookie</dc:creator>
      <dc:date>2024-02-14T15:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to close the correct tables with "On close" when running the same script multiple times?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724341#M90645</link>
      <description>&lt;P&gt;How it works: In your original example,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt; New window() &amp;lt;&amp;lt; On close(
			Close(TableA, nosave);
			Close(TableB, nosave);
		) ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;TableA and TableB are variables holding pointers to the tables. If there multiple instances, the variables point to the last instance that was assigned.&lt;/P&gt;
&lt;P&gt;In &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp; example,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(EvalExpr(
	New Window() &amp;lt;&amp;lt; On close(
		Try(Close(Expr(TableA), nosave));
		Try(Close(Expr(TableB), nosave));
	)
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;your script is being preprocessed by the Eval(EvalExpr( ... Expr(...) ) ) code to replace the variable with its value. This makes the script no longer dependent on the variable's current variable because the call to close() now uses a constant value (obtained from the variable much earlier.)&lt;/P&gt;
&lt;P&gt;How to read it: EvalExpr(...) looks through its argument for Expr(...) and evaluates them, leaving the evaluated result in place of Expr(). When EvalExpr is done, it returns an expression which still needs to be evaluated to make the OnClose(...) method run.&lt;/P&gt;
&lt;P&gt;It is important to position the Expr(...) markers at the right place; the part that needs to be cast into stone is just the variable's value. If you use Expr(close(tableA,nosave)), for example, the close() function would run too soon.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 18:06:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724341#M90645</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2024-02-14T18:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to close the correct tables with "On close" when running the same script multiple times?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724533#M90724</link>
      <description>&lt;P&gt;Thank you Craige for the explanations, very helpful! I have generalized this and am happy that the correct tables are closed upon closing the window.&lt;/P&gt;&lt;P&gt;I still have a problem that is probably somehow related: on these windows I set menu scripts in order to allow drill-down, now they call the correct arguments thanks to the&amp;nbsp;Eval(EvalExpr(...Expr(...))) code. Nevertheless I define variables inside these scripts for data manipulation purpose and I don't know how to avoid them being overwritten: i&lt;SPAN&gt;s there a way to declare these variables as local to this script ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(
	EvalExpr(
		NewWindow("Example", Outline = OutlineBox("Add-ins", Tabs = TabBox())) &amp;lt;&amp;lt;
		On close(
			Try(Close(Expr(TableA), nosave));
			Try(Close(Expr(TableB), nosave));
		)
	)
);

Outline &amp;lt;&amp;lt; Set Menu Script(
	{"Script1", Eval(EvalExpr(Add_in_table = Expr(TableA) &amp;lt;&amp;lt; Subset(Selected Rows))) ; 
	
	// some code
	
	TableD = Add_in_table &amp;lt;&amp;lt; Summary(...) ; 
	
	Eval(
		EvalExpr(
			NewWindow(Graph builder()) &amp;lt;&amp;lt; OnClose(
				Try(Close(Expr(Add_in_table), nosave));
				Try(Close(Expr(TableD), nosave));
			)
		)
	)}
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 15:49:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724533#M90724</guid>
      <dc:creator>rcookie</dc:creator>
      <dc:date>2024-02-16T15:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to close the correct tables with "On close" when running the same script multiple times?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724541#M90730</link>
      <description>&lt;P&gt;Names Default To Here(1); at the start of script or maybe using window scope (or box). Scripting Guide has some information regarding namespaces and scopes&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/global-and-local-variables.shtml#" target="_self"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/global-and-local-variables.shtml#&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-scoping-and-namespaces.shtml#" target="_self"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-scoping-and-namespaces.shtml#&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/scoped-names.shtml#" target="_self"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/scoped-names.shtml#&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You can move to different pages from left side menu&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1708101078634.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/61172i488E9E6F24313DA6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1708101078634.png" alt="jthi_0-1708101078634.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;or top right arrows&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1708101086555.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/61173iBFEC91E270D849C5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1708101086555.png" alt="jthi_1-1708101086555.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 16:31:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-close-the-correct-tables-with-quot-On-close-quot-when/m-p/724541#M90730</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-02-16T16:31:33Z</dc:date>
    </item>
  </channel>
</rss>

