cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
FabioSaragoni
Level II

How to prompt user to name SQL query output data table and add date and time to filename?

Dear all,

I am asking for your expert advice on the following topic, since I am really new to JMP scripting.

 

I made a SQL query (invisible) through the Query builder but I need help to:

 

- prompt the user to insert data table file name (pop-up window);

- add date and time (ddmonyyyy:h:m:s) to the output data table

 

What I managed to script is here below:

Names Default To Here( 1 );
dt=New SQL Query(
	Version( 130 ),
	Connection(
		"ODBC:DSN=DB001.00.G_FE_JMP15;DBQ=Y:\OFFICIAL_DATABASES\QA_Admin\Stability\DB001.00.G.StabilityStudies_FE_StudiesCompiler_JMP15.accdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;"
	),
	QueryName( "Query_DB001.00.G.StabilityStudies_FE_StudiesCompiler_10Jun2021" ),
	Select(
Column( "StudyID", "t1" ),
		Column( "TimePointID", "t1" ),
		Column( "StabilityClimaticConditions", "t1" ),
		Column( "TestMonth", "t1" ),
		Column( "ProgramComments", "t1" ),
		Column( "Test1", "t1" ),
		Column( "Test1Specification", "t1" ),
		Column( "Test1Units", "t1" ),
		Column( "Test 01", "t1" ),
		Column( "intTest1", "t1" ),
		Column( "Test2", "t1" ),
		Column( "Test2Specification", "t1" ),
		Column( "Test2Units", "t1" ),
		Column( "Test 02", "t1" ),
		Column( "intTest2", "t1" ),
		Column( "Test3", "t1" ),
		Column( "Test3Specification", "t1" ),
		Column( "Test3Units", "t1" ),
		Column( "Test 03", "t1" ),
		Column( "intTest3", "t1" ),
		Column( "Test4", "t1" ),
		Column( "Test4Specification", "t1" ),
		Column( "Test4Units", "t1" ),
		Column( "Test 04", "t1" ),
		Column( "intTest4", "t1" ),
		Column( "Test5", "t1" ),
		Column( "Test5Specification", "t1" ),
		Column( "Test5Units", "t1" ),
		Column( "Test 05", "t1" ),
		Column( "intTest5", "t1" ),
From( Table( "qry_ResultsUnion01_35", Alias( "t1" ) ) ),
	Where(
		EQ(
			Column( "StudyID", "t1" ),
			_AllRows_,
			UI(
				Comparison(
					Base(
						"Continuous",
						Prompt(
							"StudyID:",
							Character,
							PromptName( "t1.StudyID_1" )
						)
					)
				)
			)
		) & In List(
			Column( "StabilityClimaticConditions", "t1" ),
			_AllRows_,
			UI(
				SelectListFilter(
					ListBox,
					Base(
						"Categorical",
						Prompt(
							"StabilityClimaticConditions:",
							Character,
							PromptName( "t1.StabilityClimaticConditions_1" )
						)
					)
				)
			)
		)
	)
	) << Run Background(invisible);


nw = New Window( "Name data table",
	<<Modal,
	<<Return Result,
	Text Box( "Insert data table file name" ),
	tableName = Text Edit Box( " ", <<set width( 400 ) )
);
If( nw["button"] == 1 & nw["tableName"] != "",
	dt << set name( nw["tableName"] ),
	dt << save as("tableName"||Format Date( Today(), "ddmonyyyy:h:m:s" )||".jmp");
	);

Many thanks,

F

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to prompt user to name SQL query output data table and add date and time to filename?

Most likely execution of your script finishes before the New Query(.

 

Try running the query in foreground instead of background OR use modal before query to get values from user and use postquery script to change the name after query finishes.

-Jarmo

View solution in original post

4 REPLIES 4
ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to prompt user to name SQL query output data table and add date and time to filename?

Try changing your last if statement to this, it both fixes your tableName reference and removes the slashes and colons that were probably causing your issue:

 

//ask where to save the file (could skip this or define it in code)
fldr = pick directory( "Select where to save the file", "$Temp" );

//Save the file
If( nw["button"] == 1 & nw["tableName"] != "",
	dt << set name( nw["tableName"] );
	dt << save as( fldr || nw["tableName"] || Format Date( Today(), "yyyymmdd" ) || "-" || Char( Hour( Today() ) ) || Char( Minute( Today() ) ) || Char( Second( Today() ) ) || ".jmp");
);

//Open directory where file was saved (not needed)
Open(fldr);
FabioSaragoni
Level II

Re: How to prompt user to name SQL query output data table and add date and time to filename?

Thanks for your reply!

I still have an issue at this level:

dt << set name( nw["tableName"] );

The error message I get is here below

FabioSaragoni_1-1623657138473.png

 

Could you please help me solve it?

 

Thanks again,

F

jthi
Super User

Re: How to prompt user to name SQL query output data table and add date and time to filename?

Most likely execution of your script finishes before the New Query(.

 

Try running the query in foreground instead of background OR use modal before query to get values from user and use postquery script to change the name after query finishes.

-Jarmo
FabioSaragoni
Level II

Re: How to prompt user to name SQL query output data table and add date and time to filename?

Executing the query in foreground solved the issue!

Thank you so much,
Fabio