Subscribe Bookmark RSS Feed

Executing a new window dialog script within a column formula

jason_paquette

Community Trekker

Joined:

Jan 26, 2015

Hello,

I have a one column ("BIN") with a bunch of different character values and each row in the dataset refers to a unique unit that was tested. Without having to transform/summarize the dataset I would like to create a column formula that prompts the user with a ListBox dialog with a set of all the unique values within the "BIN" column. After selecting the desired values in the ListBox, the units that have a value within the "BIN" column will have a value of 1 set for the generated column ("BIN_DISPOSITION"), and the columns that units that do not have a "BIN" value that matches the ListBox selection will have a value of 0 set to the generated column ("BIN_DISPOSITION").

Example:


In the case that the user runs the formula column and selects "BIN2" and "BIN3", the following output is desired.

Unit#
BINBIN_DISPOSITION (generated by Column Formula)

Unit1

BIN10
Unit2BIN21
Unit3BIN21
Unit4BIN10
Unit5BIN31

Script:

bin_values_all = {};

bin_values_all_sorted = {};

bin_values_selected = {};

If(Row() == 1,

For Each Row(If(!Contains(bin_values_all, :BIN[Row()]),

Insert Into(bin_values_all, :BIN[Row()])

 

);

bin_values_all_sorted = Sort Ascending(bin_values_all);

New Window("BIN Value Selection", Modal,

Outline Box("BIN Value Selection",

lb = List Box(

bin_values_all_sorted

),

Button Box("OK",

bin_values_selected = lb << GetSelected

 

);

If(Contains(bin_values_selected, :BIN),

1,

0

);

I had to add the conditional If(Row() == 1...) so that the dialog and list generation did not run more than once, but it seems that my variable declarations above this would be re-initialized each time, which is not what I want.


I wasn't quite sure if there was a built-in way to do this or not.

Wondering if anyone has any ideas.

Thanks,

JP

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

I figured out how to get this working.

Instead of initializing the lists before the first conditional statement, I put them in the Row()==1 case and converted them to global variables using the prefix '::'.

If(Row() == 1,

::bin_values_all = {};

::bin_values_all_sorted = {};

::bin_values_selected = {};

For Each Row(If(!Contains(bin_values_all, :BIN[Row()]),

Insert Into(bin_values_all, :BIN[Row()])

 

);

bin_values_all_sorted = Sort Ascending(bin_values_all);

New Window("BIN Value Selection", Modal,

Outline Box("BIN Value Selection",

lb = List Box(

bin_values_all_sorted

),

Button Box("OK",

bin_values_selected = lb << GetSelected

 

);

If(Contains(bin_values_selected, :BIN),

1,

0

);

1 REPLY
Solution

I figured out how to get this working.

Instead of initializing the lists before the first conditional statement, I put them in the Row()==1 case and converted them to global variables using the prefix '::'.

If(Row() == 1,

::bin_values_all = {};

::bin_values_all_sorted = {};

::bin_values_selected = {};

For Each Row(If(!Contains(bin_values_all, :BIN[Row()]),

Insert Into(bin_values_all, :BIN[Row()])

 

);

bin_values_all_sorted = Sort Ascending(bin_values_all);

New Window("BIN Value Selection", Modal,

Outline Box("BIN Value Selection",

lb = List Box(

bin_values_all_sorted

),

Button Box("OK",

bin_values_selected = lb << GetSelected

 

);

If(Contains(bin_values_selected, :BIN),

1,

0

);