<?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: What is wrong in my function call? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419720#M66869</link>
    <description>&lt;P&gt;Check Function from Scripting Index and from &lt;A href="https://www.jmp.com/support/help/en/16.1/#page/jmp/programming-functions.shtml?os=win&amp;amp;source=application&amp;amp;utm_source=helpmenu&amp;amp;utm_medium=application#ww5013741" target="_blank" rel="noopener"&gt;Programming Functions - Function&lt;/A&gt; . Also check &lt;A href="https://www.jmp.com/content/dam/jmp/documents/en/support/jmp161/scripting-guide.pdf" target="_blank" rel="noopener"&gt;Scripting Guide&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently you have PartID as only argument and partDataTable as local variable for getDataTable4PartID which you don't use. Most likely you want to have the function defined with something like this to have to arguments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;getDataTable4PartID = Function( {PartID, partDataTable}, &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After getting that sorted out, you have to figure out how to use the arguments in the expression inside the function. For PartID you want to concatenate it into the SQL-query and partDataTable you want to use directly in the Open Database:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Open Database(
		"Driver=SQL Server;
		Server=XAB-SQL02;
		DATABASE=TBSDF;
		Trusted_Connection=Yes;",
		"SELECT * FROM dbo.View_BBX a WHERE a.Part like '"||PartID||"' AND a.TestDateTime &amp;gt; '2021-02-01'",
	partDataTable // no need for quotes here
    );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Sep 2021 18:03:53 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-09-21T18:03:53Z</dc:date>
    <item>
      <title>What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419704#M66867</link>
      <description>&lt;P&gt;I am learning how to write and call a functions in JMP (coming from Matlab).&lt;/P&gt;&lt;P&gt;Trying to pull data for a tested part from database via a SQL query.&lt;/P&gt;&lt;P&gt;Wrote two separate scripts. One is a function with PartID as the input variable and the test data table as output.&lt;/P&gt;&lt;P&gt;Other script is the function call, but I do not seem to be able to pass the partID to the function. Where I am going wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My function call&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;partDataTable = getDataTable4partID("PART16.0009")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My function&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;getDataTable4PartID = Function( {PartID},{partDataTable}, 
Open Database(
		"Driver=SQL Server;
		Server=XAB-SQL02;
		DATABASE=TBSDF;
		Trusted_Connection=Yes;",
		"SELECT * FROM dbo.View_BBX a WHERE a.Part like 'PartID' AND a.TestDateTime &amp;gt; '2021-02-01'",
		"partDataTable" // name of the output data table
    );
    
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The SQL query itself works when PartID is replaced by the actual part number PART16.0009 and run separately spitting the desired data table, but when I use the function call, the data table still has 'PartID' in the Source/ Update From DB scripts in the empty data table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:37:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419704#M66867</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2023-06-10T23:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419720#M66869</link>
      <description>&lt;P&gt;Check Function from Scripting Index and from &lt;A href="https://www.jmp.com/support/help/en/16.1/#page/jmp/programming-functions.shtml?os=win&amp;amp;source=application&amp;amp;utm_source=helpmenu&amp;amp;utm_medium=application#ww5013741" target="_blank" rel="noopener"&gt;Programming Functions - Function&lt;/A&gt; . Also check &lt;A href="https://www.jmp.com/content/dam/jmp/documents/en/support/jmp161/scripting-guide.pdf" target="_blank" rel="noopener"&gt;Scripting Guide&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently you have PartID as only argument and partDataTable as local variable for getDataTable4PartID which you don't use. Most likely you want to have the function defined with something like this to have to arguments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;getDataTable4PartID = Function( {PartID, partDataTable}, &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After getting that sorted out, you have to figure out how to use the arguments in the expression inside the function. For PartID you want to concatenate it into the SQL-query and partDataTable you want to use directly in the Open Database:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Open Database(
		"Driver=SQL Server;
		Server=XAB-SQL02;
		DATABASE=TBSDF;
		Trusted_Connection=Yes;",
		"SELECT * FROM dbo.View_BBX a WHERE a.Part like '"||PartID||"' AND a.TestDateTime &amp;gt; '2021-02-01'",
	partDataTable // no need for quotes here
    );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 18:03:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419720#M66869</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-21T18:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419802#M66873</link>
      <description>&lt;P&gt;Thanks. This works. However, I noted that having partDataTable with quotes also works fine. Is is supposed to be like this?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 19:40:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419802#M66873</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2021-09-21T19:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419805#M66874</link>
      <description>&lt;P&gt;If you have it in quotes it will most likely name your datatable to partDataTable and not with the name you wanted (if you wanted to have it as an argument).&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 19:46:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419805#M66874</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-21T19:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419806#M66875</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;. Hmm, but I am getting the name I want the output data table to be called (i.e. the same as my partID).&amp;nbsp; This is my function call.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;partDataTable = getDataTable4partID("PART16.0009","PART16.0009")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 19:56:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419806#M66875</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2021-09-21T19:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419810#M66876</link>
      <description>&lt;P&gt;I just realized something and need to confirm if this is indeed the case. After making a change in the function, it appears that I need to run the function once for the changes to be applied. Just saving does not seem to be enough. Is this correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had applied the quotes to&amp;nbsp;&lt;SPAN&gt;partDataTable and saved my function. The function call worked as expected with the data table name I desire. But after running the function&amp;nbsp;once, when I run the function call again, I get what you said I would get, i.e.&amp;nbsp;partDataTable as the name of the data table file generated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 20:03:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419810#M66876</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2021-09-21T20:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419863#M66879</link>
      <description>&lt;P&gt;Yes (if I understand the question), the function "function(...)" must be executed to replace the compiled function in the variable it is assigned to, getDataTable4PartID in your example.&lt;/P&gt;&lt;P&gt;If that was as unclear as it looks, ask again...&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="Write Your Own Functions" uid="49052" url="https://community.jmp.com/t5/JSL-Cookbook/Write-Your-Own-Functions/m-p/49052#U49052" 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; might be interesting too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 22:38:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419863#M66879</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-09-21T22:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419994#M66886</link>
      <description>&lt;P&gt;Yes, you will have to run the function once to get it "updated".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want the datatable to be named same as the PartID then you can just use one argument in the function. Here is a bit more complete example with quotes and without quotes version:&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);

getDataTable4PartID_withQuotes = Function({PartID}, 
	Open Database("connectionstring",
		"
		select '" || PartID || "' as value
		from dual
		",
		"PartID"
	);
);

partDataTable_withQuotes = getDataTable4PartID_withQuotes("PART16.0009");
Show(partDataTable_withQuotes);

getDataTable4PartID = Function({PartID}, 
	Open Database("connectionstring",
		"
		select '" || PartID || "' as value
		from dual
		",
		PartID
	);
);

partDataTable = getDataTable4PartID("PART16.0009");
Show(partDataTable);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For me these are printed to the log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;partDataTable_withQuotes = DataTable("PartID");
partDataTable = DataTable("PART16.0009");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JMP will return the datatable from the function (as it is the "last" line), but I don't feel comfortable trusting it so I would use local reference in function and then return the reference and the final function would be something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;getDataTable4PartID = Function({PartID}, {dtTemp},
	dtTemp = Open Database("connectionstring",
		"select '" || PartID || "' as value
		from dual",
		PartID
	);
	return(dtTemp);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 09:42:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/419994#M66886</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-22T09:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421070#M66982</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;.&amp;nbsp;I am having two issues with what you have suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I call the function&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);
getDataTable4PartID = Function({PartID}, {dtTemp},
	dtTemp = Open Database("connectionstring",
		"select '" || PartID || "' as value
		from dual",
		PartID
	);
	return(dtTemp);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as&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;DataTable4PartID = getDataTable4PartID("PART16.0009");&lt;/CODE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get a data table with expected/correct data but the data table is called UntitledXX (XX happens to be 24 in my case).&lt;/P&gt;&lt;P&gt;Also, note that I had to comment&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;Names Default To Here(1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;without which the function call did not work. Not sure what is going on....any help would be very useful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 23:15:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421070#M66982</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2021-09-25T23:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421212#M67003</link>
      <description>&lt;P&gt;If Names Default To Here(1); breaks your script there is most likely something wrong with the namespaces. You should almost always start JSL scripts with Names Default To Here(1) and it shouldn't break anything.&lt;/P&gt;&lt;P&gt;My guess is that it is defined in wrong place (or called in wrong place), order of execution does matter with JSL.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 04:27:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421212#M67003</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-27T04:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421241#M67009</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;. All my scripts and functions have the first line as&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It just happens (as mentioned in my previous post), this particular function did not run without commenting the above line.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In any case, if I use your suggested function, I&amp;nbsp;&lt;SPAN&gt;get a data table with expected/correct data but the data table is called UntitledXX (XX happens to be 24 in my case). Any help to fix this would be very helpful. Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 09:03:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421241#M67009</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2021-09-27T09:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong in my function call?</title>
      <link>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421365#M67018</link>
      <description>&lt;P&gt;Adding&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;include ("getDataTable4partID.jsl");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;before the function call&amp;nbsp;seems to have solved all the issues I have ben having.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 14:47:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/What-is-wrong-in-my-function-call/m-p/421365#M67018</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2021-09-27T14:47:53Z</dc:date>
    </item>
  </channel>
</rss>

