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
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");
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.
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);
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");
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
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);
Works great, thanks!!
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.