cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
CTrahon0526
Level II

Script to enter new row data in popup window.

Hi,

 

I am looking to have a script produce a popup window for a user to enter data that will be added to a new row. The user only needs to add data in certain columns. I am close with the script but can't figure out how to get it to work. Added the data table with my script attempt.

 

Any help will be appreciated, thanks in advance!

 

Regards,

Chris

3 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Script to enter new row data in popup window.

I would use Data table subscripting in case like this

Names Default To Here(1);

dt = Current Data Table();

// present choices to user
nw = New Window("Add New Row Data",
	<<Modal,
	Panel Box("Row Data",
		Lineup Box(N Col(2),
			Text Box("Chamber ID"),
			v1 = Number Edit Box(401.1),
			Text Box("Pct WW Down (put 0 if CHx 100% up)"),
			v2 = Number Edit Box(0),
			Text Box("Reason"),
			v3 = Text Edit Box("Enter Text Here"),
			Text Box("Year"),
			v4 = Number Edit Box(2023),
			Text Box("Work Week"),
			v5 = Number Edit Box(1),
			Text Box("Scheduled or Unscheduled"),
			v6 = Text Edit Box("Unscheduled")
		)
	), 
	V List Box(
		Lineup Box(N Col(2),
			Button Box("Click to Add Row", // this script runs when the button is pressed...
				vals = {};
				Insert Into(vals, v1 << Get);
				Insert Into(vals, v2 << Get);
				Insert Into(vals, v3 << Get Text);
				Insert Into(vals, v4 << Get);
				Insert Into(vals, v5 << Get);
				Insert Into(vals, v6 << Get Text);
				dt << Add Rows(1);
				dt[N Rows(dt), {"CH ID", "Pct WW DWN", "Reason", "Year", "WW", "Sched/Unsch"}] = vals;
               //{:CH ID = v1, Pct WW DWN = v2, Reason = v3, Year = v4, WW = v5, Sched/Unsch = "Scheduled"});
			),
			Button Box("Cancel")
		);
	)
);

Also hints might be useful with Text Edit Boxes for you (and if you want to force users to add something there, you have to handle that also)

Names Default To Here(1);
win = New Window("Example", text = Text Edit Box(""));
text << Set Hint("Enter your name");
-Jarmo

View solution in original post

txnelson
Super User

Re: Script to enter new row data in popup window.

Here is one way to handle this

Names Default To Here( 1 );

// present choices to user
dlg = New Window( "Add New Row Data",
	<<Modal,
	Panel Box( "Row Data",
		Lineup Box( N Col( 2 ),
			Text Box( "Chamber ID" ),
			v1 = Number Edit Box( 401.1 ),
			Text Box( "Pct WW Down (put 0 if CHx 100% up)" ),
			v2 = Number Edit Box( 0 ),
			Text Box( "Reason" ),
			v3 = Text Edit Box( "Enter Text Here" ),
			Text Box( "Year" ),
			v4 = Number Edit Box( 2023 ),
			Text Box( "Work Week" ),
			v5 = Number Edit Box( 1 ),
			Text Box( "Scheduled or Unscheduled" ),
			v6 = Text Edit Box( "Unscheduled" )
		)
	), 
	
	Lineup Box( N Col( 2 ),
		Button Box( "Click to Add Row", // this script runs when the button is pressed...
                  
			dt = Current Data Table();
              
                    
			dt << Add Rows( 1 );
			dt:chid[N Rows( dt )] = v1 << Get;
			dt:pct ww dwn[N Rows( dt )] = v2 << Get;
			dt:reason[N Rows( dt )] = v3 << Get text;
			dt:year[N Rows( dt )] = v4 << Get;
			dt:ww[N Rows( dt )] = v5 << Get;
			dt:"sched/unsch"n[N Rows( dt )] = v6 << Get text;
               //{:CH ID = v1, Pct WW DWN = v2, Reason = v3, Year = v4, WW = v5, Sched/Unsch = "Scheduled"});
			//dlg << closeWindow; // just the dialog, not the report
			Window( "Add New Row Data" ) << closeWindow;
	
		),
		Button Box( "Cancel", Window( "Add New Row Data" ) << closeWindow );
			
				
	)
			
);

Please take the time to read through the Scripting Guide.  It will give you a big leg up on being able to solve such questions.

Jim

View solution in original post

jthi
Super User

Re: Script to enter new row data in popup window.

It is possible, but how to implement depends on your script. You can use << Get Property("List Check") to get the property from column and then get first argument of that and you should have the list of values. You can then use << Set Items to the combo box to update values.

Below is example using your original data table

Names Default To Here(1);

dt = Open("$DOWNLOADS/AddRowWindowScript.jmp");

nw = New WIndow("",
	cb = Combo Box({"a", "b", "c"});
);

wait(1); // for demo purposes

lc_vals = Column(dt, "Sched/Unsch") << Get Property("List Check");
list_to_cb = Arg(lc_vals, 1);
cb << Set Items(list_to_cb);
-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Script to enter new row data in popup window.

I would use Data table subscripting in case like this

Names Default To Here(1);

dt = Current Data Table();

// present choices to user
nw = New Window("Add New Row Data",
	<<Modal,
	Panel Box("Row Data",
		Lineup Box(N Col(2),
			Text Box("Chamber ID"),
			v1 = Number Edit Box(401.1),
			Text Box("Pct WW Down (put 0 if CHx 100% up)"),
			v2 = Number Edit Box(0),
			Text Box("Reason"),
			v3 = Text Edit Box("Enter Text Here"),
			Text Box("Year"),
			v4 = Number Edit Box(2023),
			Text Box("Work Week"),
			v5 = Number Edit Box(1),
			Text Box("Scheduled or Unscheduled"),
			v6 = Text Edit Box("Unscheduled")
		)
	), 
	V List Box(
		Lineup Box(N Col(2),
			Button Box("Click to Add Row", // this script runs when the button is pressed...
				vals = {};
				Insert Into(vals, v1 << Get);
				Insert Into(vals, v2 << Get);
				Insert Into(vals, v3 << Get Text);
				Insert Into(vals, v4 << Get);
				Insert Into(vals, v5 << Get);
				Insert Into(vals, v6 << Get Text);
				dt << Add Rows(1);
				dt[N Rows(dt), {"CH ID", "Pct WW DWN", "Reason", "Year", "WW", "Sched/Unsch"}] = vals;
               //{:CH ID = v1, Pct WW DWN = v2, Reason = v3, Year = v4, WW = v5, Sched/Unsch = "Scheduled"});
			),
			Button Box("Cancel")
		);
	)
);

Also hints might be useful with Text Edit Boxes for you (and if you want to force users to add something there, you have to handle that also)

Names Default To Here(1);
win = New Window("Example", text = Text Edit Box(""));
text << Set Hint("Enter your name");
-Jarmo
CTrahon0526
Level II

Re: Script to enter new row data in popup window.

Hey Jarmo,

 

Just building off of this request.

 

Is there a way to have the Combo Box options automatically update based on List Check values in that column?

 

Thanks,

Chris

jthi
Super User

Re: Script to enter new row data in popup window.

It is possible, but how to implement depends on your script. You can use << Get Property("List Check") to get the property from column and then get first argument of that and you should have the list of values. You can then use << Set Items to the combo box to update values.

Below is example using your original data table

Names Default To Here(1);

dt = Open("$DOWNLOADS/AddRowWindowScript.jmp");

nw = New WIndow("",
	cb = Combo Box({"a", "b", "c"});
);

wait(1); // for demo purposes

lc_vals = Column(dt, "Sched/Unsch") << Get Property("List Check");
list_to_cb = Arg(lc_vals, 1);
cb << Set Items(list_to_cb);
-Jarmo
CTrahon0526
Level II

Re: Script to enter new row data in popup window.

Works great, thanks!!

txnelson
Super User

Re: Script to enter new row data in popup window.

Here is one way to handle this

Names Default To Here( 1 );

// present choices to user
dlg = New Window( "Add New Row Data",
	<<Modal,
	Panel Box( "Row Data",
		Lineup Box( N Col( 2 ),
			Text Box( "Chamber ID" ),
			v1 = Number Edit Box( 401.1 ),
			Text Box( "Pct WW Down (put 0 if CHx 100% up)" ),
			v2 = Number Edit Box( 0 ),
			Text Box( "Reason" ),
			v3 = Text Edit Box( "Enter Text Here" ),
			Text Box( "Year" ),
			v4 = Number Edit Box( 2023 ),
			Text Box( "Work Week" ),
			v5 = Number Edit Box( 1 ),
			Text Box( "Scheduled or Unscheduled" ),
			v6 = Text Edit Box( "Unscheduled" )
		)
	), 
	
	Lineup Box( N Col( 2 ),
		Button Box( "Click to Add Row", // this script runs when the button is pressed...
                  
			dt = Current Data Table();
              
                    
			dt << Add Rows( 1 );
			dt:chid[N Rows( dt )] = v1 << Get;
			dt:pct ww dwn[N Rows( dt )] = v2 << Get;
			dt:reason[N Rows( dt )] = v3 << Get text;
			dt:year[N Rows( dt )] = v4 << Get;
			dt:ww[N Rows( dt )] = v5 << Get;
			dt:"sched/unsch"n[N Rows( dt )] = v6 << Get text;
               //{:CH ID = v1, Pct WW DWN = v2, Reason = v3, Year = v4, WW = v5, Sched/Unsch = "Scheduled"});
			//dlg << closeWindow; // just the dialog, not the report
			Window( "Add New Row Data" ) << closeWindow;
	
		),
		Button Box( "Cancel", Window( "Add New Row Data" ) << closeWindow );
			
				
	)
			
);

Please take the time to read through the Scripting Guide.  It will give you a big leg up on being able to solve such questions.

Jim