Reading parameter value from DB
You can easily read the value of flowchart block's or agent's parameter from a specific cell of a database table.
Assume we have
block that processes parts of different types, and the processing time differs depending on the part type.
We have the processing times for each part stored in the
If you have your data stored in an external database, first
them into the built-in AnyLogic database.
Now we can set our
block to read the required processing time for each part type from the database table.
To read the flowchart block's parameter from the DB
- We want the
block to use the processing time specific for the type of the currently processed part. This requires us to create a custom agent type for parts. To create a new agent type, in the
view, right-click the model item, and choose
New > Agent Type
from the context menu. You will see the
wizard. On the first page, set the
Agent type name:
Part. On the second page, choose the animation shape for this agent, and on the next page add a parameter:
String. We will use this parameter to store the part type. Let your
block generate agents of
field), and let it
Set agent parameters from DB
(you will find the detailed information
- Open the
- For the
property, we want to switch from the value editor to the DB reference constructor. To do this, on the left of the
field, click the
button, and choose
option from the popup list.
- In the
control below, select the database table containing the data:
- From the
drop-down list, choose the column of the table that contains the data you need:
- Below, you will see the
section where you can define a condition that specifies what particular value to select from the specified table column.
- We want to select the value corresponding to the specific part, so we will use values from the
column to find the required record. Therefore, choose
from the drop-down list.
- In the field below, type
Let us explain how it works. We have set the block to take a look at the built-in database for the
value. The value is taken from
column. Our agents of type
storing the part type (it could be "Part A", "Part B", or "Part C"). For each new agent entering the
Delay, the block will search in the specified database table for the record that has the value in the
column equal to the
of the agent currently being processed by the block (it is accessed as
agent). This value is set as the delay time for the current agent.
For example, if the current agent has name "Part B", the block will set the delay time equal to 20 seconds. If the database contains several records with "Part B" value in the
column, you will see the error message since AnyLogic expects the values in this column to be unique.