cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
aserino
Level III

Integrating a Query Builder script (with a post-query script) into another script

Hello,

 

I've been using query builder and graph builder to put together some scripts that constantly pull data off a server, plot, and save results (in JMP 13). Recently, I've been trying to tie several of these scripts into a single script that runs all of them at once using Include(), which works fine. The problem I'm facing now is all the directories have been hard coded, and I'd like to use something like: Get Default Directory() so that this broader collection of scripts can be moved onto other computers.

 

Unfortunately, I've run into the following problems:

-When Get Default Directory() is used within the 'Post-Query Script' it returns  '/ ' , no matter where this script is saved.

-When saving data tables/graphs created in the post-query script that to variables, those variables don't seem to exist (or are not accessible) outside of the

post-query script.

-Any variables created outside of the post-query script cannot be used inside it.

 

// Main File

directory = Get Default Directory();

fileNames = Files In Directory( directory );

For( iFile = 1, iFile <= N Items( fileNames ), iFile++, 

	filename = fileNames[iFile];

	If( Ends With( filename, ".jsl" ), 

		Include( directory || script_folder || filename, invisible );

	);

);
// Example Post-Query File section

gb = Graph Builder( 
     // graph details

);
// directory = Get Default Directory(); // Another method attempted

myPath = directory || "Report\";
myName = "Example";
fileName = myPath || myName || ".pptx";
myTemplate = directory || "Template.pptx";

Report( gb ) << save presentation( fileName, Template( myTemplate ), Outline Titles( "Hide" ) );

gb << close window;
Close All( data tables );

Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: Integrating a Query Builder script (with a post-query script) into another script

Your post contains several items to address:

  1. If you are working on Windows, Get Default Directory(), is not getting the last directory used. If your program prompts, use Set Default Directory, then Get Default Directory() will return this value. 
  2. I recommend using a namespace or a global Associative Array, to maintain references/variables.  If more than one instance of your program is running at any one time, make it an anonymous namespace, so that it is unique for each instance.  For an associative array, ::varRef_aa = Associative Array(); ::varRef_aa << Set Default Value(-9999);  Then in your script specify ::varRef_aa[a] = 1;  A benefit of using a NameSpace is that an unintended Clear Globals() does not delete the namespace nor its contents.
  3.  I am not a fan of Save Presentation because every object is saved on a different page and there is very little control for scaling. I use a free external program called P3ICLI. So typically, I create an output directory, unique for the task or report, then save the view that I want to a picture in that directory. I am bringing up his method, because by saving the output you want, as slide 1, 2, etc. , you can use Save Presentation, by creating a list of Files in Directory()  for that that saved directory,  and in a for loop appending them to your PPTX using Save Presentation. Also, by saving a picture, you could have a multi-object display, saved and when using Save Presentation, all items are on the same page.  It offers some control of the PPTX report.

 

Finally, yes, it is annoying that Open Database(connect_str, ...) and Create Database Connection(connect_str) can use the same connect string that requires the trailing slash, yet New SQL Query() requires the trailing slash be removed and a prefix of ODBC: if connecting to a database.

//--- Method 3: New SQL Query platform script -----------------------------------
//remove the trailing slash on importpath
importnoslash = substr(connect_str, 1, length(connect_str)-1 ); 
nconnect = "ODBC:" || importnoslash

Just a few ideas.

   

View solution in original post

3 REPLIES 3
aserino
Level III

Re: Integrating a Query Builder script (with a post-query script) into another script

Adding another example:

 

dir = Get Default Directory();
query = Open( dir || "query.jmpquery", Private );
query << Run(
	On Run Complete(
		queryResult << // some function
		a = 1
	)
);
Write( a );  //  variable is unknown

Creating a variable inside Run() isn't accessible outside of Run()

gzmorgan0
Super User (Alumni)

Re: Integrating a Query Builder script (with a post-query script) into another script

Your post contains several items to address:

  1. If you are working on Windows, Get Default Directory(), is not getting the last directory used. If your program prompts, use Set Default Directory, then Get Default Directory() will return this value. 
  2. I recommend using a namespace or a global Associative Array, to maintain references/variables.  If more than one instance of your program is running at any one time, make it an anonymous namespace, so that it is unique for each instance.  For an associative array, ::varRef_aa = Associative Array(); ::varRef_aa << Set Default Value(-9999);  Then in your script specify ::varRef_aa[a] = 1;  A benefit of using a NameSpace is that an unintended Clear Globals() does not delete the namespace nor its contents.
  3.  I am not a fan of Save Presentation because every object is saved on a different page and there is very little control for scaling. I use a free external program called P3ICLI. So typically, I create an output directory, unique for the task or report, then save the view that I want to a picture in that directory. I am bringing up his method, because by saving the output you want, as slide 1, 2, etc. , you can use Save Presentation, by creating a list of Files in Directory()  for that that saved directory,  and in a for loop appending them to your PPTX using Save Presentation. Also, by saving a picture, you could have a multi-object display, saved and when using Save Presentation, all items are on the same page.  It offers some control of the PPTX report.

 

Finally, yes, it is annoying that Open Database(connect_str, ...) and Create Database Connection(connect_str) can use the same connect string that requires the trailing slash, yet New SQL Query() requires the trailing slash be removed and a prefix of ODBC: if connecting to a database.

//--- Method 3: New SQL Query platform script -----------------------------------
//remove the trailing slash on importpath
importnoslash = substr(connect_str, 1, length(connect_str)-1 ); 
nconnect = "ODBC:" || importnoslash

Just a few ideas.

   

pmroz
Super User

Re: Integrating a Query Builder script (with a post-query script) into another script

You should consider creating an addin for your application.  That will solve your problem of where the files are located.  An addin associates an alias with a file location.  If your addin "alias" is com.company.dept.mygreatapp, you can refer to files like this:

include("$ADDIN_HOME(com.company.dept.mygreatapp)\DoSomethingGreat.jsl");