cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to loop through rows of data table based on user input with wild card in order to load data from database for each selected row item

I have a data table with first column filled with part_IDs (other columns have got other info about corresponding to each part) and a working function which loads test data for a given (single) part_ID from the database.  I would like to have the following functionality via a modal window.

1. Have the user select the part_IDs in the data table using a wild card. For example, the part_IDs are of the form- A0012, A0013, A0014 and so on and then B7001, B7002, B7003 and so on. The user needs to be able to just specify something like A00* or B70* and select the corresponding part_IDs in the data table where * is the wild card character.

2.  Once the part_IDs are selected, I would like to loop through each of them and get the test data via my function (which takes the part_ID as input and returns the test data in a data table) and then concatenate each new data table below the previous to get a final data table (note all test data table have identical column names)

How to implement this in JSL?

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to loop through rows of data table based on user input with wild card in order to load data from database for each selected row item

For part one this might get you started

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(6),
	Compress File When Saved(1),
	New Column("ID",
		Character,
		"Nominal",
		Set Values({"A001", "A002", "A003", "B001", "B002", "B003"})
	)
);

nw = New Window("", << modal, << return result,
	v list box(
		teb = text edit box("A00*"),
		h list box(
			Button Box("OK"),
			Button Box("Cancel"),
		)
	)
);

If(nw["Button"] != 1,
	stop();
);

// no real idea behind the selection logic, so we will use very simple one
// user has to always provide *
user_input = nw["teb"];
If(!Contains(user_input, "*"),
	Throw("No wild card provided!");
);

user_rows = dt << Get Rows Where(Starts With(:ID, Substitute(nw["teb"], "*", "")));
user_ids = dt[user_rows, "ID"];

Concatenation is easy to do by letting JMP create script for it. Then just add references and maybe make it into a function

-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: How to loop through rows of data table based on user input with wild card in order to load data from database for each selected row item

For part one this might get you started

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(6),
	Compress File When Saved(1),
	New Column("ID",
		Character,
		"Nominal",
		Set Values({"A001", "A002", "A003", "B001", "B002", "B003"})
	)
);

nw = New Window("", << modal, << return result,
	v list box(
		teb = text edit box("A00*"),
		h list box(
			Button Box("OK"),
			Button Box("Cancel"),
		)
	)
);

If(nw["Button"] != 1,
	stop();
);

// no real idea behind the selection logic, so we will use very simple one
// user has to always provide *
user_input = nw["teb"];
If(!Contains(user_input, "*"),
	Throw("No wild card provided!");
);

user_rows = dt << Get Rows Where(Starts With(:ID, Substitute(nw["teb"], "*", "")));
user_ids = dt[user_rows, "ID"];

Concatenation is easy to do by letting JMP create script for it. Then just add references and maybe make it into a function

-Jarmo