question

shanice.c avatar image
0 Likes"
shanice.c asked Felix Möhlmann commented

How to wait for event until conditional is true?

In my AGV process flow, AGV is waiting in standby point in the beginning, so I use wait for event activity to control. I have a table used to record all tasks for AGVs, I want to check if AGV still has any tasks to do after completing one. I'd like to use a condition like:

int getTaskID = query("SELECT MAX(TaskID)FROM TaskTable WHERE AGVID = tempAGV AND Done = 0");

if(getTaskID>0){

AGV will execute a new task.

}else

stay in standbypoint.

1631095078234.png

I would like to know which event I should use? The object field is token.agv. I want to fill in the if statement above for the event field. Also, for the if statement, how could I let AGV leave/stay in wait for event activity if that statement is true/false. I think I'd like to use "return", but I still couldn't find a suitable event to use.

1631094532617.png



0907.fsm

FlexSim 21.2.2
process flowwait for eventflexsim 21.2.2
1631094532617.png (25.3 KiB)
1631095078234.png (55.2 KiB)
0907.fsm (586.0 KiB)
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

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Felix Möhlmann commented

As the name of the activity suggest, "Wait for Event" reacts to a distinct event triggering and can decide whether to send the token onwards based on parameters of that event. It can not directly be used to continuously check for a condition.

What you might do instead, is use a "Decide" activity in the place of the "Wait for Event". In there you can use you code to return which connection the token should be send to next. If no task is available, the token can then enter into a "Wait for Event" that reacts to a new entry being added to the table and routes the token back to the "Decide" activity to reevaluate the condition.

As there is (to my knowledge) no event for a row being added to a global table, you will have to listen to something else. If I'm not mistaken, rows currently get added by a custom code activity in another process flow. You could have the "Wait for Event" listen for a token exiting that activity, because if that happens, a new row will have been added to the table. Or you listen to a token entering that activity (as it currently doesn't lead anywhere). In that case put a 0-second delay after the "Wait for Event" to be sure the code of the other activity has finished before the token is send to the "Decide".

Another alternative would be to send a message to the process flow (or some other object) in the same place where the table rows are added and listen for that message.

1631101504537.png


1631101504537.png (30.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.