How to store field values from a list into an array

How to store field values from a list into an array

stefano_l
Not applicable
119 Views
3 Replies
Message 1 of 4

How to store field values from a list into an array

stefano_l
Not applicable

[ FlexSim 19.0.0 ]

Hi, I'm trying to store field values (not the header) from a list into an array. In particular, I pushed items in a list called ListBox and now I want to store values of Dimension field into an array.

22971-cattura.jpg

Is there a way to do it?

Thank you in advance for your answer.

0 Likes
Accepted solutions (1)
120 Views
3 Replies
Replies (3)
Message 2 of 4

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

You can get access to the list entries by a table.query and the clause ARRAY_AGG()

Array myArray = Table.query("SELECT ARRAY_AGG(Dimension) FROM ItemList1")[1][1];

this is shortest way to get the entries of a field of a list.

My first Approach is a bit longer. You do a Table.query for the List. Then you clone the result table into an array. Unfortunately the array is 2-dimensional. You append each result cell value in a one dimensional array by an iter( ..) - ation.

The table.query works only on global lists.

22972-list-field-into-array.jpg

global-list-field-to-an-array.fsm

Message 3 of 4

stefano_l
Not applicable

@Jörg Vogel Thank you for your answer, I'm using a global list. How can I do it by script?

0 Likes
Message 4 of 4

joerg_vogel_HsH
Mentor
Mentor
Array myArrayAlt = Table.query("SELECT $2",
	rslt.length, 
	myArray.push(rslt.shift()[1])).clone()[1][1];

an alternative source code line