<?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 add a button to open a script in another folder. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639316#M83692</link>
    <description>&lt;P&gt;this might help: try using "include" instead of "open".&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 );

dir=Get Path Variable( "SAMPLE_SCRIPTS" );
file_name = "chaosGame.jsl";
file_path = Char(Dir || file_name);
show(file_path);
Current Journal() &amp;lt;&amp;lt; Append( Button Box("Chaos Game", include (file_path)))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Jun 2023 07:47:41 GMT</pubDate>
    <dc:creator>Byron_JMP</dc:creator>
    <dc:date>2023-06-06T07:47:41Z</dc:date>
    <item>
      <title>How to add a button to open a script in another folder.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639291#M83690</link>
      <description>&lt;P&gt;Hi all, how can i make it such that whenever i click a button i placed in a journal it will run the script that is located in another folder.&lt;/P&gt;&lt;P&gt;Using a test script below i am able to successfully open script in another folder. This is on JMP16.&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 );
Clear Log();

Dir = Get Default Directory();

file_name = "JMP script/Load_PD.jsl";

file_path = Char(Dir || file_name);

Open(file_path);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using the test scrip i made i tried to implement it to my main script as shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script shown below is just a snippet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;LoadTableType = Function( {reportType}, 
	Dir = Get Default Directory();
	If(
		reportType == "PD",
		file_name = "JMP script/Load_PD.jsl";
		file_path = Char(Dir || file_name);
		show(file_path);
		Current Journal() &amp;lt;&amp;lt; Append( Button Box("Load PD Table", Open (file_path))),
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However after the main code finishes running and the button is generated, each time i click the button i keep getting this error shown below:&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;Name Unresolved: file_path in access or evaluation of 'file_path' , file_path/*###*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would greatly appreciate any advice given thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:11:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639291#M83690</guid>
      <dc:creator>Dyan</dc:creator>
      <dc:date>2023-06-09T16:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a button to open a script in another folder.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639316#M83692</link>
      <description>&lt;P&gt;this might help: try using "include" instead of "open".&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 );

dir=Get Path Variable( "SAMPLE_SCRIPTS" );
file_name = "chaosGame.jsl";
file_path = Char(Dir || file_name);
show(file_path);
Current Journal() &amp;lt;&amp;lt; Append( Button Box("Chaos Game", include (file_path)))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2023 07:47:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639316#M83692</guid>
      <dc:creator>Byron_JMP</dc:creator>
      <dc:date>2023-06-06T07:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a button to open a script in another folder.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639319#M83693</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4386"&gt;@Byron_JMP&lt;/a&gt;&amp;nbsp; Thanks for your suggestion but i am still getting the same error&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Name Unresolved: file_path in access or evaluation of 'file_path' , file_path/*###*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2023 08:02:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639319#M83693</guid>
      <dc:creator>Dyan</dc:creator>
      <dc:date>2023-06-06T08:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a button to open a script in another folder.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639642#M83718</link>
      <description>&lt;P&gt;You've got a button box that has an attached script -- &lt;CODE class=" language-jsl"&gt;Open( file_path )&lt;/CODE&gt;.&amp;nbsp; Think of that script as a piece of paper.&amp;nbsp; Now think of clicking on the button as starting a new blank-slate JMP instance.&amp;nbsp; In this new instance, you ask it to run the script that's on this piece of paper.&amp;nbsp; When running that script, it finds the name &lt;CODE class=" language-jsl"&gt;file_path&lt;/CODE&gt; and does a name-lookup.&amp;nbsp; Being a complete blank-state, it cannot determine what &lt;CODE class=" language-jsl"&gt;file_path&lt;/CODE&gt; is supposed to mean, so it throws an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clearly this is not exactly what happens, but it is the case that when the button is clicked the attached script is run in a scope that is not the same scope as when you created the button.&amp;nbsp; This is true for all display box scripts.&amp;nbsp; They won't know anything about the scope / variables that were present when the display box was created -- the attached scripts / functions run in a new completely separate scope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An easy fix is to use &lt;CODE class=" language-jsl"&gt;Eval( Eval Expr( ... Expr( ... ) ... ) )&lt;/CODE&gt;, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;LoadTableType = Function( {reportType}, 
	Dir = Get Default Directory();
	If(
		reportType == "PD",
		file_name = "JMP script/Load_PD.jsl";
		file_path = Char(Dir || file_name);
		Eval( Eval Expr(
			Current Journal() &amp;lt;&amp;lt; Append( Button Box( "Load PD Table", Open( Expr( file_path ) ) ) )
		) )
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;this pre-evaluates the name file_path so that the script doesn't see a name but rather a string with the correct path.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 20:48:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-add-a-button-to-open-a-script-in-another-folder/m-p/639642#M83718</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2023-06-06T20:48:26Z</dc:date>
    </item>
  </channel>
</rss>

