question

Patrick Cloutier avatar image
0 Likes"
Patrick Cloutier asked Phil BoBo edited

How to dynamically copy list entries to a table

I'm looking to copy the entries on a list to a table every X seconds so that I can later make stats on those entries.

I know how to create a loop in a process flow that reads a custom code every X seconds and I know how to write to a table.

What I'm missing is the command to read the list content.

Thanks,

FlexSim 18.1.2
process flowlist
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Arun Kr avatar image
4 Likes"
Arun Kr answered Phil BoBo edited

Hi Patrick Cloutier,

You can write an SQL query to pull/copy the data from the list and dump the queried data into the global table.

Table Result = Table.query("SELECT * FROM ListName");
result.cloneTo(Table("QueryDump"));

Regards,

Arun KR

· 8
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Patrick Cloutier avatar image Patrick Cloutier commented ·

Will this overwrite the data every time I copy or will it append to the table? I need that second option.

0 Likes 0 ·
Patrick Cloutier avatar image Patrick Cloutier commented ·

My list is called People and my table is called CountCor2 so I wrote:

Table result = Table.query("SELECT * FROM People");

result.cloneTo(Table("CountCor2"));

And I get the error message:

Property "dataType" accessed on invalid node and it erases the content of the table.

What am I doing wrong ?

0 Likes 0 ·
Patrick Cloutier avatar image Patrick Cloutier commented ·

That error was when my code was in a userevent. I put the code in the process flow instead and it works.

But as indicated earlier, I need to append to the table and not overwrite it. How can I do that?

0 Likes 0 ·
Arun Kr avatar image Arun Kr Patrick Cloutier commented ·

Hi Patrick Cloutier,

I was thinking how the appending and overwriting makes a difference. Can you explain more on your requirement?

0 Likes 0 ·
Patrick Cloutier avatar image Patrick Cloutier Arun Kr commented ·

Every X seconds I want the content of the list to be copied to a table without erasing what was copied X seconds earlier. The table keeps getting longer and longer.

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel commented ·

You clone the tables to arrays. Then you append one to the other. And finally you make a table query over the array to get a table again.

0 Likes 0 ·
Patrick Cloutier avatar image Patrick Cloutier Joerg Vogel commented ·

OK I made it work. I cloneto the list to a table and then I append this table to another table using a for loop that I created.

It works EXCEPT that some of the columns in my table are in pointer format so I need to convert them to string format. I tried tostring() but it doesn't work.

Here is the statement that works:

Table("CountCor2Append")[lastrow+i][1] = Table("CountCor2")[i][1];

How do I convert to string at the same time?

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Patrick Cloutier commented ·

Cast the value to a treenode and call getPath():

Table("GlobalTable1")[1][1].as(treenode).getPath()

Also, you don't need to use the intermediate table. Just use a for() loop to iterate through the returned query result Table rather than cloning it and then using a for() loop through the clone.

4 Likes 4 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.