question

Ruben M4 avatar image
0 Likes"
Ruben M4 asked Ruben M4 commented

Problems trying to create new rows for each new label value...

global table question.fsmscreenshot-4.pngI would like that for each new value of the label "destination_deliveryDate" a row is created to make a counter of the times that the values of this label are repeated. I have tried to do it the way you can see in the image and in the attached file.

FlexSim 19.2.4
global tableswrite to global table
· 1
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·
It is currently not so easy to find, but in triggers there is a picklist template that does exactly what you try. This templates append a new line for each event to a global table and write a value in this new cell. Perhaps you can learn from the default source code there.
0 Likes 0 ·

1 Answer

Roi Sánchez avatar image
0 Likes"
Roi Sánchez answered Ruben M4 commented

Hi @Ruben M4 , replace your code inside your Custom Code activity to this new one:

Table table = Table("GlobalTable1");
string row = token.destination_deliveryDate;
string col = "Col 1";

int aux = 0;

if (table.numRows > 0){
int i;
for(i=1; i<=table.numRows; i++){
if (table.getRowHeader(i) == row){
table[row][col]++;
aux = 1;
}
}
if (aux == 0){
table.addRow();
table.setRowHeader(table.numRows, row);
table[row][col] = 1;
}
}
else{
table.addRow();
table.setRowHeader(table.numRows, row);
table[row][col] = 1;
}

I basically check for every row in the table if its rowName header is the same as the current label of the token running the code. If not, I create a new row.

Remember to delete all Rows in the table in the Reset trigger to prevent it from overlapping its data.

· 1
5 |100000

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

Ruben M4 avatar image Ruben M4 commented ·

Thank you so much. It runs perfectly.

0 Likes 0 ·