Decide code where the connector value is determined

Decide code where the connector value is determined

H3xod
Not applicable
59 Views
3 Replies
Message 1 of 4

Decide code where the connector value is determined

H3xod
Not applicable

[ FlexSim 23.0.3 ]

Hi,

I need some help in order to find the right syntax to write the code for a Decide function(process flow) .

I have successfully written the code with several conditions but i want to push back the limit a bit by being able to redirect the token item to the connector assigned to it in the Excel File, and that is where i am stuck, cant seem to have the right logic ...

Here is a sample of the Excel file i use :


IDmenuiserieNumCadreFamilleTypeCU
11Accessoire1Dormant4
16Accessoire1Ouvrant4
3089CoulissantOuvrant2
3090CoulissantDormant2
2382FrappeOuvrant3
2347FrappeDormant3


the first code i have tried for multiple conditions is this one :

Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);

Variant case_val1 = token.Produit.Type;
Variant case_val2 = token.Produit.Famille;
Variant Connector = 0;

if (case_val1 == "Dormant" && case_val2 == "Coulissant") 
{
     Connector = 2;
}

if (case_val1 == "Ouvrant" && case_val2 == "Coulissant") 
{
     Connector = 3;
}

if (case_val1 == "Dormant" && case_val2 == "Frappe") 
{
     Connector = 1;
}

if (case_val1 == "Ouvrant" && case_val2 == "Frappe")
{
     Connector = 2;
}

if (case_val1 == "Accessoire*")
{
     Connector = 4;
}

return Connector;


it works, but like i said i want to be able to use the variable defined in the data table "CU" for the connector.

Therefore i have tried this, to no avail...

Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);


Variant case_val1 = token.Produit.Type;
Variant case_val2 = token.Produit.Famille;
Variant Connector = 0;

for(int i=1; i<=Table("ProcessFlow/Source%").numRows; i++)
{
    if (case_val1 == "Dormant" && case_val2 == "Coulissant") 
    {
        Connector = token.Produit.CU;
        return Connector;
    }

    if (case_val1 == "Ouvrant" && case_val2 == "Coulissant") 
    {
        Connector = token.Produit.CU;
        return Connector;
    }

    if (case_val1 == "Dormant" && case_val2 == "Frappe") 
    {
        Connector = token.Produit.CU;
        return Connector;
    }

    if (case_val1 == "Ouvrant" && case_val2 == "Frappe")
    {
        Connector = token.Produit.CU;
        return Connector;
    }

    if (case_val1 == "Accessoire*")
    {
        Connector = token.Produit.CU;
        return Connector;
    }
}


I will attach the fsm and xls file to the this question.

0 Likes
Accepted solutions (1)
60 Views
3 Replies
Replies (3)
Message 2 of 4

allister_wilson
Not applicable
Accepted solution

It looks like the tokens going through the Decide activity all have a CU label assigned by the source :

1675910966181.png

If you want them all to go through the connector corresponding to their CU value, you can just use that label directly in the decision :

1675911075619.png

Is this the behaviour you want?

Message 3 of 4

H3xod
Not applicable
thanks so much, i cant believe how much i have been beating around the bush :D

and just for argument's sake what would be the right syntax if i ever wanted to write it in code?

0 Likes
Message 4 of 4

allister_wilson
Not applicable
You'd get the same result within a custom code field with :
return token.CU;
0 Likes