Patrick Zweekhorst avatar image
Patrick Zweekhorst asked Patrick Zweekhorst commented

Childexpfolder never exists anymore in endOfReplicationTrigger


When running the experimenter, in the On End Of Replication trigger it was always useful to know if the code was executed in the main process or in the child process. To check this, we would use the following line of code:

if (objectexists(childexpfolder)) { // End of Replication on the main process

Our problem in FlexSim 2022 is that the childexpfolder never exists. So, we can’t use this check anymore. This line of code is also still used in the “Write to global Table” dropdown option in the End Of Replication Trigger.

What is the correct way to check if you are in in main or child process in 2022?

Thank you in advance,


FlexSim 22.0.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.

1 Answer

Jordan Johnson avatar image
Jordan Johnson answered Patrick Zweekhorst commented

You are correct, and that is certainly a bug. I added it to the dev list, and it should be fixed soon. Once the bug is fixed, the if statement will work correctly, as it did before.

Note: All following code examples will be obsolete when this bug is fixed. It may not work in future versions.

The bug is that the childexpfolder is being deleted before the On End Of Replication trigger is called. So this creates two problems. First, it leads directly to your question: how do you check if you are in the child or parent process? The best way I can think of is to check the command line parameters:

if (commandlineparam("maintenance") == "childexperiment") { // in the child

The second problem is how to pass custom data up to the parent, and do something with it. Once this bug is fixed, you can add custom data to the subnodes of the Experimenter object in the model, and then read it on the other side. But since that folder is being deleted too soon, you'll need another approach.

The best way right now is to use the repData node in the code for a Performance Measure. This code is designed to allow you to shove whatever data you want into that node. As an example, I made a performance measure with this code for its value:

/**Custom Code*/
treenode reference = param(1);
treenode extraData = param(2);
treenode repData = param(3);

if (repData) {
    repData.subnodes.assert("custom data", [1, 2, 3]);

return 1;

Note that while you can add subnodes to the repData node, the value of that node will be overwritten with the return value.

The repData node is then transferred back to the main process, and saved in the database So in the On End Of Replication trigger, on the parent side, you can get it back out of the database by querying:

/**Custom Code*/
Object current = ownerobject(c);
int replication = param(1);
int scenario = param(2);
treenode childexpfolder = param(3);
Map task = param(4);

if (commandlineparam("maintenance") == "childexperiment") { // in the child
    // the data can be shoved in a pfm, so do nothing here
} else {
    // the data has been stored in the database, so get it out
    Database.Connection db = function_s(ownerobject(c), "getDBConnection");
    // load all the pfm nodes from the database into the tree
    int taskID = task.taskID;

    treenode container = Model.find("Tools").subnodes.assert("pfms");
    string stmtText = "\
        SELECT name, loadnode(node, ?) \
        FROM pfms p JOIN pfm_values pv ON = pv.pfm_id \
        WHERE pv.task_id = ? \
    var stmt = db.prepareStatement(stmtText);
    if (stmt) {
        stmt.bindParam(1, container, Database.DataType.Unknown);
        stmt.bindParam(2, taskID, Database.DataType.Unknown);
        var result = stmt.execute();
        while (result.fetchNext()) {
            result[2].name = result[1];

The point of this code is to show how to get the pfm repData nodes out of the database. The query loads the saved data as subnodes of the container node. This code is meant as a starting point; you'll probably want to customize it for what you're doing.


· 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.

Patrick Zweekhorst avatar image Patrick Zweekhorst commented ·
Hi @Jordan Johnson ,

Thank you for your extensive answer. I am sure we will get it working for our case.

0 Likes 0 ·

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.