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 :

  1. Object current = param(1);
  2. treenode activity = param(2);
  3. Token token = param(3);
  4. treenode processFlow = ownerobject(activity);
  5.  
  6. Variant case_val1 = token.Produit.Type;
  7. Variant case_val2 = token.Produit.Famille;
  8. Variant Connector = 0;
  9.  
  10. if (case_val1 == "Dormant" && case_val2 == "Coulissant")
  11. {
  12. Connector = 2;
  13. }
  14.  
  15. if (case_val1 == "Ouvrant" && case_val2 == "Coulissant")
  16. {
  17. Connector = 3;
  18. }
  19.  
  20. if (case_val1 == "Dormant" && case_val2 == "Frappe")
  21. {
  22. Connector = 1;
  23. }
  24.  
  25. if (case_val1 == "Ouvrant" && case_val2 == "Frappe")
  26. {
  27. Connector = 2;
  28. }
  29.  
  30. if (case_val1 == "Accessoire*")
  31. {
  32. Connector = 4;
  33. }
  34.  
  35. 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...

  1. Object current = param(1);
  2. treenode activity = param(2);
  3. Token token = param(3);
  4. treenode processFlow = ownerobject(activity);
  5.  
  6.  
  7. Variant case_val1 = token.Produit.Type;
  8. Variant case_val2 = token.Produit.Famille;
  9. Variant Connector = 0;
  10.  
  11. for(int i=1; i<=Table("ProcessFlow/Source%").numRows; i++)
  12. {
  13.     if (case_val1 == "Dormant" && case_val2 == "Coulissant") 
  14.     {
  15.         Connector = token.Produit.CU;
  16.         return Connector;
  17.     }
  18.  
  19.     if (case_val1 == "Ouvrant" && case_val2 == "Coulissant") 
  20.     {
  21.         Connector = token.Produit.CU;
  22.         return Connector;
  23.     }
  24.  
  25.     if (case_val1 == "Dormant" && case_val2 == "Frappe") 
  26.     {
  27.         Connector = token.Produit.CU;
  28.         return Connector;
  29.     }
  30.  
  31.     if (case_val1 == "Ouvrant" && case_val2 == "Frappe")
  32.     {
  33.         Connector = token.Produit.CU;
  34.         return Connector;
  35.     }
  36.  
  37.     if (case_val1 == "Accessoire*")
  38.     {
  39.         Connector = token.Produit.CU;
  40.         return Connector;
  41.     }
  42. }


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.