Exiting a Branch (or Loop or the AL Flow)
If you want to exit a Branch, Loop, or Switch, or even built-in Branches like the AL Flow section, you use the system.exitBranch() method from a place where we can script, for example, a Hook, or even a Script Component. Calling system.exitBranch() with no parameters (or with an empty string) will cause the containing Branch to exit, and flow continues with the first component after the Branch. We can also provide the method with a string parameter containing either:
There is also a continue functionality in Loop Components. The following methods are available in the system object:
- One of the reserved keywords: Branch, Loop, Flow, Cycle or AssemblyLine (case insensitive)
- This will break the first Branch of this type, tracing backwards up the AssemblyLine. So if your script code is in a Branch within a Loop, and you execute the call system.exitBranch("Loop"), you will exit both the Branch and the Loop containing it. Using the reserved word Flow causes the flow to exit the Flow section of the AssemblyLine, continuing either to the response behavior in the case of a Server Mode Connector or to an active Iterator to read in the next entry, or to AL shutdown (Epilogs, …). The Cycle keyword passes control to the end of the current AL cycle, and does not invoke response behavior in Server Mode Connectors, while the AssemblyLine keyword will cause the AL to stop and shutdown.
All other values used in the system.exitBranch() call cause a break out of the branch/loop having the specified name. So, for example, the call system.exitBranch("IF_LookupOk") sends the flow after the containing Branch or Loop called “IF_LookupOk”. Note that unlike system.skipTo(), which will pass control to any named AL component, system.exitBranch() will cause processing to continue after the specified Loop/Branch.
- The name of a Branch or Loop (case sensitive)
- If you pass the name of a Branch or Loop in which your script call is nested, then control will pass to the component following it in the AL. If no Branch or Loop with this name is found, tracing backwards from the point of the call, then an error results.
system.continueLoop(); system.continueLoop(name);where name is a case-sensitive string, indicating a Loop name. In the case where a Loop name is provided, the program flow is transferred to the Loop Component with that name.
Parent topic:
Branch Components