question

Borja Lorenzo avatar image
0 Likes"
Borja Lorenzo asked Felix Möhlmann answered

How to access the value of a specific label from all subnodes

Hello everyone

Is there a way to access all the labels of the subnodes and check if any of the values are equal to 1, and then apply the logic in the Decide? The goal is to use a property or method to avoid writing or developing a loop in custom code. It's important to consider that the number of subnodes can vary, so I want to make it dynamic.

1731786788605.png

Festo_base1 is the main item, and when it reaches a decision point, the SourceEvent is triggered, and I assign the token name as token.plataforma.

FlexSim 24.1.1
labelssubnodescondicional decide
1731786788605.png (72.0 KiB)
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

Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered

You can use a query to get the number of items with a specific label value in a single expression.

Table.query("SELECT $2 FROM $1 WHERE Type == 1", token.plataforma, $iter(1)).numRows

See the documentation linked below ("Advanced Query Techniques", about half way down the page).

https://docs.flexsim.com/en/24.2/Reference/DeveloperAdvancedUser/SQLQueries/SQLQueries.html

Though a for-loop will have a faster execution speed.

Another option would be to store the total per label value in an Array/Table/Map, so you can just read it whenever. This would be the faster option if the quantity is queried regularly compared to how often the content actually changes.

5 |100000

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