question

h3xod avatar image
0 Likes"
h3xod asked Allister Wilson commented

Decide code where the connector value is determined

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 :


IDmenuiserie NumCadre Famille Type CU
1 1 Accessoire1 Dormant 4
1 6 Accessoire1 Ouvrant 4
30 89 Coulissant Ouvrant 2
30 90 Coulissant Dormant 2
23 82 Frappe Ouvrant 3
23 47 Frappe Dormant 3


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.

FlexSim 23.0.3
flexscript codingprocess flow decide
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

·
Allister Wilson avatar image
1 Like"
Allister Wilson answered Allister Wilson commented

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?


1675910966181.png (12.9 KiB)
1675911075619.png (16.1 KiB)
· 2
5 |100000

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

h3xod avatar image h3xod commented ·
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 0 ·
Allister Wilson avatar image Allister Wilson h3xod commented ·
You'd get the same result within a custom code field with :
return token.CU;
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.