<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: FIFO order with custom code and process flow in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491432#M8859</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I already fix it, and works the same as the one you give above. But when i simulate it for a long time, i notice that after cluster 2 and 4 empty, the crane won't send the box to cluster 1 and 3 after it (cluster 1 and 3 empty) and the entire system didn't in FIFO order anymore.&lt;/P&gt;
 &lt;P&gt;So I decided to add some code in the custom code.&lt;/P&gt;
 &lt;PRE&gt;/**Custom Code*/
Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);


int CurrContent = Model.find("Cluster 1").subnodes.length;
int CurrContent2 = Model.find("Cluster 3").subnodes.length;
int CurrContent3 = Model.find("Cluster 2").subnodes.length;
int CurrContent4 = Model.find("Cluster 4").subnodes.length;
int MaxContent = Model.find("Cluster 1").as(Object).getProperty("MaxContent");
int MaxContent2 = Model.find("Cluster 3").as(Object).getProperty("MaxContent");
int MaxContent3 = Model.find("Cluster 2").as(Object).getProperty("MaxContent");
int MaxContent4 = Model.find("Cluster 4").as(Object).getProperty("MaxContent");
int CurrContent5 = Model.find("Queue3").subnodes.length;
int stream = getstream(activity);
double randomnum = uniform(0.0, 40.0, stream);
double total = 0.0;

if (CurrContent5 &amp;lt; 6 ) {
token.item.destination = Model.find("Queue2");
}
else if(CurrContent &amp;lt; MaxContent){
token.item.destination = Model.find("Cluster 1");
}
else if(CurrContent2 &amp;lt; MaxContent2){
token.item.destination = Model.find("Cluster 3");
}
else if(CurrContent3 &amp;lt; MaxContent3){
token.item.destination = Model.find("Cluster 2");
}
else if(CurrContent4 &amp;lt; MaxContent4){
token.item.destination = Model.find("Cluster 4");
}
else{
total += 20;
if (randomnum &amp;lt;= total){
token.item.destination = Model.find("Cluster 2");
}
else{
token.item.destination = Model.find("Cluster 4");
}
}

&lt;/PRE&gt;
 &lt;P&gt;But when i try it, seems like it didn't work and the box won't enter the cluster queue after a long time. Which line should i fix in here?&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 05 Oct 2021 13:24:25 GMT</pubDate>
    <dc:creator>andre_t6</dc:creator>
    <dc:date>2021-10-05T13:24:25Z</dc:date>
    <item>
      <title>FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491427#M8854</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 21.2.2 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Hi everyone,&lt;BR /&gt;In my model, i want to make my crane to move item from the cluster to Queue2 in FIFO order with custom code in process flow, but it seems like there is something i miss in the code so that the model didn't work properly and the crane didn't move at all. I tried recreate the process flow but the crane still didn't move.&lt;/P&gt;
 &lt;P&gt;Can someone check where did i go wrong in the model?&lt;BR /&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/44500-fifo-model.fsm" target="_blank"&gt;FIFO Model.fsm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sun, 03 Oct 2021 19:16:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491427#M8854</guid>
      <dc:creator>andre_t6</dc:creator>
      <dc:date>2021-10-03T19:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491428#M8855</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;The queues are not set to push the items to the list, so the token can't pull anything from it. Change the "Use Transport" option from using the "STRE" object (which doesn't actually exist in the model as far as I can tell) to pushing the items to the list. This will also automatically write the priority and destination label to the item.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1633328675594.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1507596iF68F66412215232C/image-size/large?v=v2&amp;amp;px=999" role="button" title="1633328675594.png" alt="1633328675594.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The "priority" label written to the item is not capitalized, but the list currently expects it to be. You also don't need an "Expression" field, a simple "Label" field will do. The capitalization of "priority" will also have to be removed from the query in the "Pull from List" activity.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1633328580123.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1507597i9E3D8149FE43B75A/image-size/large?v=v2&amp;amp;px=999" role="button" title="1633328580123.png" alt="1633328580123.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In the unload activity the destination is given by "token.destination" (the default value), but the label is actually present on the item, so you have to use "token.item.destination".&lt;/P&gt;&lt;P&gt;Finally, there are some minor errors in your custom code. &lt;/P&gt;&lt;P&gt;- The names of the cluster queues contain a space in front if the number. In the find-commands, this space is missing.&lt;BR /&gt;- In line 11 you are trying to get the property "MaxContent2" of one of the queues. This doesn't exist. You surely mean to determine the "MaxContent" as in the line above.&lt;/P&gt;&lt;P&gt;(Note that currently "Queue1" is set to a higher priority than the cluster. I don't know if this is correct.)&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/44502-fifo-model-1.fsm" target="_blank"&gt;fifo-model_1.fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Oct 2021 06:32:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491428#M8855</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2021-10-04T06:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491429#M8856</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Thanks for your detail explanation. That's really helpful&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Oct 2021 02:51:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491429#M8856</guid>
      <dc:creator>andre_t6</dc:creator>
      <dc:date>2021-10-05T02:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491430#M8857</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I tried to recreate this model, but why the crane didn't pick up the box from queue1 while queue1 have the higher priority than the other?&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Oct 2021 06:00:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491430#M8857</guid>
      <dc:creator>andre_t6</dc:creator>
      <dc:date>2021-10-05T06:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491431#M8858</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Hard to tell without looking at your model. Is the query in the "Pull from List" correct (label field added to list, lower case "p" in priority)? Do you get any error messages?&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Oct 2021 13:08:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491431#M8858</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2021-10-05T13:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491432#M8859</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I already fix it, and works the same as the one you give above. But when i simulate it for a long time, i notice that after cluster 2 and 4 empty, the crane won't send the box to cluster 1 and 3 after it (cluster 1 and 3 empty) and the entire system didn't in FIFO order anymore.&lt;/P&gt;
 &lt;P&gt;So I decided to add some code in the custom code.&lt;/P&gt;
 &lt;PRE&gt;/**Custom Code*/
Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);


int CurrContent = Model.find("Cluster 1").subnodes.length;
int CurrContent2 = Model.find("Cluster 3").subnodes.length;
int CurrContent3 = Model.find("Cluster 2").subnodes.length;
int CurrContent4 = Model.find("Cluster 4").subnodes.length;
int MaxContent = Model.find("Cluster 1").as(Object).getProperty("MaxContent");
int MaxContent2 = Model.find("Cluster 3").as(Object).getProperty("MaxContent");
int MaxContent3 = Model.find("Cluster 2").as(Object).getProperty("MaxContent");
int MaxContent4 = Model.find("Cluster 4").as(Object).getProperty("MaxContent");
int CurrContent5 = Model.find("Queue3").subnodes.length;
int stream = getstream(activity);
double randomnum = uniform(0.0, 40.0, stream);
double total = 0.0;

if (CurrContent5 &amp;lt; 6 ) {
token.item.destination = Model.find("Queue2");
}
else if(CurrContent &amp;lt; MaxContent){
token.item.destination = Model.find("Cluster 1");
}
else if(CurrContent2 &amp;lt; MaxContent2){
token.item.destination = Model.find("Cluster 3");
}
else if(CurrContent3 &amp;lt; MaxContent3){
token.item.destination = Model.find("Cluster 2");
}
else if(CurrContent4 &amp;lt; MaxContent4){
token.item.destination = Model.find("Cluster 4");
}
else{
total += 20;
if (randomnum &amp;lt;= total){
token.item.destination = Model.find("Cluster 2");
}
else{
token.item.destination = Model.find("Cluster 4");
}
}

&lt;/PRE&gt;
 &lt;P&gt;But when i try it, seems like it didn't work and the box won't enter the cluster queue after a long time. Which line should i fix in here?&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Oct 2021 13:24:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491432#M8859</guid>
      <dc:creator>andre_t6</dc:creator>
      <dc:date>2021-10-05T13:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491433#M8860</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;I found the problem. Because the "Send to Port" of Queue1 is set to "First Available", the items virtually reserve space in the cluster queues despite getting moved to Queue2 directly. As a result, Queue1 stops pushing the items to the list when all space in the cluster is reserved.&lt;/P&gt;&lt;P&gt;To fix this, have it push the items to the list in the "Send to Port" rather the transport option. This means however, that the priority label is not automatically added to the items. You'll have to do this in another trigger (On Entry for example)&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/44558-fifo-model-11.fsm" target="_blank"&gt;fifo-model-1(1).fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Oct 2021 16:59:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491433#M8860</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2021-10-05T16:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: FIFO order with custom code and process flow</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491434#M8861</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Thanks for your help. I really appreciated that
&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Oct 2021 02:17:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/fifo-order-with-custom-code-and-process-flow/m-p/13491434#M8861</guid>
      <dc:creator>andre_t6</dc:creator>
      <dc:date>2021-10-06T02:17:09Z</dc:date>
    </item>
  </channel>
</rss>

